Hello:
I have your module in my application. Compiled with exceptions disabled and -O2 optimization.
I was trying to read an invalid JSON file:
{ "sn": 1, "name": "First bird" "type": 1, "flags": { "tied_down": true } }
const std::ifstream config_file(argv[1]); nlohmann::json j; config_file >> j;
The application dumps core in the last line instead of returning an error:
Program received signal SIGABRT, Aborted. __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50 50 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory. (gdb) bt #0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50 #1 0x00007f0de58f8899 in __GI_abort () at abort.c:79 #2 0x000055d061bb677d in nlohmann::detail::json_sax_dom_callback_parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> >::parse_error (this=<optimized out>, this=<optimized out>, ex=...) at /usr/include/c++/9/bits/basic_string.h:1936 #3 nlohmann::detail::json_sax_dom_parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> >::parse_error (this=<optimized out>, this=<optimized out>, ex=...) at /develop/build/_deps/nlohmann_json-src/single_include/nlohmann/json.hpp:4806 #4 nlohmann::detail::parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> >::sax_parse_internal<nlohmann::detail::json_sax_dom_parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> > > (this=<optimized out>, sax=<optimized out>) at /develop/build/_deps/nlohmann_json-src/single_include/nlohmann/json.hpp:8987 #5 0x000055d061bb6dbc in nlohmann::detail::parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> >::parse ( this=0x7fff73960a80, strict=<optimized out>, result=...) at /usr/include/c++/9/bits/stl_vector.h:94 #6 0x000055d061bb76c3 in nlohmann::operator>> (i=..., j=...) at /develop/build/_deps/nlohmann_json-src/single_include/nlohmann/json.hpp:9104 #7 0x000055d061ba888a in main (argc=2, argv=0x7fff73960ee8) at /develop/apps/apps/test_application/src/test_application.cpp:33
- Is this expected behavior?
- If yes, what is the proper usage of the class so that the application doesn't dump core and returns an error instead?
Thank you.
Hello:
I have your module in my application. Compiled with exceptions disabled and -O2 optimization.
I was trying to read an invalid JSON file:
{ "sn": 1, "name": "First bird" "type": 1, "flags": { "tied_down": true } }const std::ifstream config_file(argv[1]); nlohmann::json j; config_file >> j;The application dumps core in the last line instead of returning an error:
Program received signal SIGABRT, Aborted. __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50 50 ../sysdeps/unix/sysv/linux/raise.c: No such file or directory. (gdb) bt #0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50 #1 0x00007f0de58f8899 in __GI_abort () at abort.c:79 #2 0x000055d061bb677d in nlohmann::detail::json_sax_dom_callback_parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> >::parse_error (this=<optimized out>, this=<optimized out>, ex=...) at /usr/include/c++/9/bits/basic_string.h:1936 #3 nlohmann::detail::json_sax_dom_parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> >::parse_error (this=<optimized out>, this=<optimized out>, ex=...) at /develop/build/_deps/nlohmann_json-src/single_include/nlohmann/json.hpp:4806 #4 nlohmann::detail::parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> >::sax_parse_internal<nlohmann::detail::json_sax_dom_parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> > > (this=<optimized out>, sax=<optimized out>) at /develop/build/_deps/nlohmann_json-src/single_include/nlohmann/json.hpp:8987 #5 0x000055d061bb6dbc in nlohmann::detail::parser<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> >::parse ( this=0x7fff73960a80, strict=<optimized out>, result=...) at /usr/include/c++/9/bits/stl_vector.h:94 #6 0x000055d061bb76c3 in nlohmann::operator>> (i=..., j=...) at /develop/build/_deps/nlohmann_json-src/single_include/nlohmann/json.hpp:9104 #7 0x000055d061ba888a in main (argc=2, argv=0x7fff73960ee8) at /develop/apps/apps/test_application/src/test_application.cpp:33Thank you.