-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Closed
Labels
documentationsolution: duplicatethe issue is a duplicate; refer to the linked issue insteadthe issue is a duplicate; refer to the linked issue insteadsolution: proposed fixa fix for the issue has been proposed and waits for confirmationa fix for the issue has been proposed and waits for confirmation
Milestone
Description
Description
When using ordered json with push_back
call, pointer to previous structure gets corrupted
Reproduction steps
Use the code bellow with nlohmann::ordered_json
to get corrupted pointer
Expected vs. actual results
Expected output (same code, without ordered json):
string
string
{"a":{"b":"test"},"c":[1]}
Actual output (corrupted pointer):
string
number
{"a":{"b":"test"},"c":[1]}
Minimal code example
#include <iostream>
#include <nlohmann/json.hpp>
using json = nlohmann::ordered_json; // use nlohmann::json to get correct result
int main()
{
auto obj = json::parse("{\"a\": {\"b\": \"test\"}}");
auto& ref = obj["a"]["b"];
std::cout << ref.type_name() << '\n'; // string
obj["c"] = json::array();
obj["c"].push_back(1);
std::cout << ref.type_name() << '\n'; // expected string, got number
std::cout << obj.dump(); // valid result, {"a":{"b":"test"},"c":[1]}
}
Error messages
No response
Compiler and operating system
Tested on ARM Windows and X64 Windows in Debug and Release modes
Library version
3.11.3
Validation
- The bug also occurs if the latest version from the
develop
branch is used. - I can successfully compile and run the unit tests.
Metadata
Metadata
Assignees
Labels
documentationsolution: duplicatethe issue is a duplicate; refer to the linked issue insteadthe issue is a duplicate; refer to the linked issue insteadsolution: proposed fixa fix for the issue has been proposed and waits for confirmationa fix for the issue has been proposed and waits for confirmation