json: Unhandled exception in test-cbor.exe Stack overflow when debugging project with Visual Studio 2019 16.7.7 compiled with c++17 or c++latest

In the file json.hpp in handle_value(Value&& v) an

Unhandled exception at 0x00007FF6D51C2CB8 in test-cbor.exe: 0xC00000FD: Stack overflow (parameters: 0x0000000000000001, 0x0000004760A69FF8).

is thrown when debugging the test-cbor project in Visual Studio 2019 16.7.7 compiled with /std:c++17 or with /c++latest

This occures, because of recursive function calls: from_cbor, sax_parse, parse_cbor_internal, get_cbor_object, parse_cbor_internal, …

Please describe the steps to reproduce the issue.

  1. unzip json-3.9.1.zip
  2. shell cd json-3.9.1
  3. mkdir build
  4. cd build
  5. cmake .. -DJSON_BuildTests=On -D JSON_Install:BOOL=OFF -D JSON_ImplicitConversions:BOOL=OFF -DCMAKE_CXX_FLAGS="/std:c++17"
  6. In test\download_test_data.vcxproj replace all cpp test -d json_test_data || with cpp if not exist json_test_data
  7. Open nlohmann_json.sln in Visual Studio 2019 16.7.7
  8. Right click test-cbor and select “Set as Startup Project” in the context menu
  9. Switch configuration to Debug
  10. Execute Build\Build solution (F7)
  11. Execute Debug\Start Debugging (F5)

What is the expected behavior?

No stack overflow

And what is the actual behavior instead?

Stack overflow

Which compiler and operating system are you using?

  • Compiler: Visual Studio 2019 16.7.7 Prof.
  • Operating system: Windows 10 2004 Pro

Which version of the library did you use?

  • latest release version 3.9.1 (zip file)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (9 by maintainers)

Most upvoted comments

I think the if (len==0) check would be safe, and would help the debug build. The compiler is probably already doing this optimization for release.

I’d rather not go for such optimizations at this point. I refactored the JSON parser to work without stack recursion a while ago, and I think the same approach can be tried for the binary formats.