Closed aslobodaNV closed 1 month ago
Thanks for the report. I'm concerned that the version of jsoncpp you're linking with might not match the header you're using. Can you verify this?
g++ -I ../../lib/third-party/json/include -Wall -std=c++17 example.cc -o example -ljsoncpp -g
In particular I'm concerned that the -ljsoncpp
is finding a "system" install.
That's what this looks like to me.
Maybe rerun that g++
command in verbose mode.
Looking at your backtraces, the libjsoncpp.so is:
/lib/x86_64-linux-gnu/libjsoncpp.so.25
Pretty sure that's the problem.
This was exactly my issue, thanks for noticing the mismatched library. I have updated my compilation command and find that I no longer can replicate the issue.
Describe the bug When adding entries to a Json::Value instance, I am seeing instances of memory corruption. I have been able to distill the behavior down to a very simple struct wherein member variables of that struct are corrupted when adding entries to a Json::Value instance.
To Reproduce The following code exhibits the errant behavior:
When this code is compiled and run with gdb, I am able to observe the corruption:
In the gdb output snippet above I see that the variable, "dev", has a member "address" with value 0x555555556004. I have printed the full contents of "dev" and added a watchpoint to the variable. I then add two new fields to the variable devJSON, an instance of Json::Value. In the process of adding the second field, the watchpoint triggers and indicates that "address" has changed to the value 0x0. I see from the backtrace that this occurred within a call to "Json::Value::initBasic(Json::ValueType, bool)". Going back up to the frame of the caller, I print out "dev" and confirm that it has been corrupted.
Expected behavior I expected no changes to the member variables of the struct "dev", especially since the change occurs when the jsoncpp calls are not interacting with the struct.
Desktop (please complete the following information): OS: Ubuntu 24.04 LTS Codename: noble Kernel: 6.8.0-31-generic
Additional context Compiled using g++-13 as follows:
g++ -I ../../lib/third-party/json/include -Wall -std=c++17 example.cc -o example -ljsoncpp -g
Removing additional fields from the definition of the Device_t struct appears to circumvent the underlying issue. I am not sure why.