boostorg / json

A C++11 library for parsing and serializing JSON to and from a DOM container in memory.
https://boost.org/libs/json
Boost Software License 1.0
424 stars 94 forks source link

Read Access Violation on copy of existing element to new element #1011

Open streetjimmothy opened 3 weeks ago

streetjimmothy commented 3 weeks ago

Version of Boost

1_84

Steps necessary to reproduce the problem

Expected Behaviour: assigning an existing property on a JSON to a key that does not exist should work the same as when the assignment is made to an existing key, or when any other value is assigned to a key that does not exist. Actual Behaviour: read access violation Case 1: object["existing_key"] = object["old_key"]; //works Case 2: object["new_key"] = "new_value"; //works Case 3: object["new_key"] = object["old_key"]; //read access violation

Call stack & Error details:

Exception thrown: read access violation. this was 0xFFFFFFFFFFFFFFFF. boost_json-vc143-mt-gd-x64-1_84.dll!boost::container::pmr::memory_resource::is_equal(const boost::container::pmr::memory_resource & other) Line 59 boost_json-vc143-mt-gd-x64-1_84.dll!boost::container::pmr::operator==(const boost::container::pmr::memory_resource & a, const boost::container::pmr::memory_resource & b) Line 66 boost_json-vc143-mt-gd-x64-1_84.dll!boost::json::value::swap(boost::json::value & other) Line 390 boost_json-vc143-mt-gd-x64-1_84.dll!boost::json::value::operator=(const boost::json::value & other) Line 268

streetjimmothy commented 3 weeks ago

As I was writing the above, I discovered that you don't get the error if any new element is assigned prior to the copy. This works: object["new_key"] = "new_value"; object["another_new_key"] = object["existing_key"]; This does not: object["another_new_key"] = object["existing_key"]; //read access violation object["new_key"] = "new_value";

grisumbras commented 3 weeks ago

Please provide a minimal complete verifiable example, so that I can attempt to reproduce the error. As is, I tried locally, and the error you are describing doesn't manifest.

streetjimmothy commented 3 weeks ago

Thanks for the quick response; I'll whip one up in the next few days