You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
[updated] - i made some progress on uncovering the root cause; updated title and description to reflect my current understanding
When linking the debug .dll and .lib (generated via vcpkg) to debug build of an Visual C++ project, any string assignment from a jsoncpp library function to the main app (also in debug mode) will cause garbage to be written and crash the app.
I believe this is due to a mismatch linking CRT between the library and the app. I can reproduce a similar behavior with other libraries (such as, say, libcurl) by linking the release version of the dll against debug build of the app. Stack Overflow has a nice explanation.
To Reproduce
install jsoncpp 1.9.5 via vcpkg on windows .\vcpkg.exe install jsoncpp:x64-windows
create simple .exe application that outputs json string, linking to the debug .lib and .dll files. I tried both with StreamWriterBuilder and FastWriter.
with StreamWriterBuilder, it crashes on assigning indentation string:
Exception thrown at 0x00007FFA8C6F1490 (vcruntime140.dll) in jsoncpptest.exe: 0xC0000005: Access violation reading location 0x000000565D9E6871.
vcruntime140.dll!00007ffa8c6f1490()
[Inline Frame] jsoncpp.dll!Json::duplicateStringValue(const char * value, unsigned __int64) Line 126
at C:\Users\david\src\vcpkg\buildtrees\jsoncpp\src\1.9.5-13b47286ba.clean\src\lib_json\json_value.cpp(126)
jsoncpp.dll!Json::Value::CZString::CZString(const Json::Value::CZString & other) Line 247
at C:\Users\david\src\vcpkg\buildtrees\jsoncpp\src\1.9.5-13b47286ba.clean\src\lib_json\json_value.cpp(247)
[Inline Frame] jsoncpp.dll!std::pair<Json::Value::CZString const ,Json::Value>::{ctor}(Json::Value::CZString & _Val2, const Json::Value &) Line 172
at C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.34.31933\include\utility(172)
jsoncpp.dll!Json::Value::resolveReference(const char * key, const char * end) Line 1069
at C:\Users\david\src\vcpkg\buildtrees\jsoncpp\src\1.9.5-13b47286ba.clean\src\lib_json\json_value.cpp(1069)
jsoncpptest.exe!main(int argc, char * * argv) Line 10
at C:\Users\david\src\jsoncpptest\main.cpp(10)
with FastWriter it crashes when write() returns NULL instead of the string.
I can confirmed that the JSON value contains the expected information.
Expected behavior
The same code works as expected on OSX.
Desktop
OS: Windows 10 Pro 21H2
Visual C++ 2022 (Visual Studio 17.4.4)
The text was updated successfully, but these errors were encountered:
whenpiqsfly
changed the title
jsoncpp_1.9.5_x64-windows (via vcpkg) string manipulation issues
jsoncpp_1.9.5_x64-windows (via vcpkg) string assignment issues
Feb 8, 2023
whenpiqsfly
changed the title
jsoncpp_1.9.5_x64-windows (via vcpkg) string assignment issues
Linking debug .dll (via vcpkg) to debug build of windows app causes string corruption issues
Feb 9, 2023
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
[updated] - i made some progress on uncovering the root cause; updated title and description to reflect my current understanding
When linking the debug .dll and .lib (generated via vcpkg) to debug build of an Visual C++ project, any string assignment from a jsoncpp library function to the main app (also in debug mode) will cause garbage to be written and crash the app.
I believe this is due to a mismatch linking CRT between the library and the app. I can reproduce a similar behavior with other libraries (such as, say, libcurl) by linking the release version of the dll against debug build of the app. Stack Overflow has a nice explanation.
To Reproduce
.\vcpkg.exe install jsoncpp:x64-windows
Expected behavior
The same code works as expected on OSX.
Desktop
The text was updated successfully, but these errors were encountered: