-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON_DIAGNOSTICS assertion for ordered_json #2962
Comments
From what I can tell, the parent pointer for the first element changes when the second element gets added to the ordered "map" container. I'm not familiar with the json code but my wild guess is pointer invalidation due to using a As an aside, thank you for this wonderful library! |
I can reproduce the issue. Interestingly, it does not occur if |
You are right, thanks for the analysis! In #2838 we fixed the library to re-evaluate the parents in case the vector for an array changed its capacity and pointers are invalidated. We forgot that the same effect can occur inside |
That would work, but would be a breaking change in the if (old_capacity != std::size_t(-1))
{
// see https://github.com/nlohmann/json/issues/2838
JSON_ASSERT(type() == value_t::array);
if (JSON_HEDLEY_UNLIKELY(m_value.array->capacity() != old_capacity))
{
// capacity has changed: update all parents
set_parents();
return j;
}
} |
I found a fix, see #2963. Feedback welcome! |
Cool! I still have to fix some linter warnings, but the fix should be merged by Monday. |
What is the issue you have?
Assertion occurs with ordered_json and
JSON_DIAGNOSTICS
when none is expectedPlease describe the steps to reproduce the issue.
Run the working example
Can you provide a small but working code example?
What is the expected behavior?
Assertion should not occur
And what is the actual behavior instead?
Assertion occurs
Which compiler and operating system are you using?
Tested on Visual Studio 2019 latest release. Also tested on godbolt with gcc 9.3, 11.2..
Which version of the library did you use?
3.10.0
The text was updated successfully, but these errors were encountered: