-
-
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
Assertion failure when inserting into arrays with JSON_DIAGNOSTICS set #2838
Comments
Oh dear, thanks for reporting! I can reproduce the issue and will try to find the missing parent update. |
@nlohmann I'm thinking that the |
@gregmarr Great analysis! I added a quick fix and the assertion does not occur any more. Before: m_value.array->push_back(std::move(val));
set_parent(m_value.array->back()); After: auto capacity = m_value.array->capacity();
m_value.array->push_back(std::move(val));
if (capacity == m_value.array->capacity())
{
set_parent(m_value.array->back());
}
else
{
for (auto& element : *m_value.array)
{
set_parent(element);
}
} I'll need some more time to prepare a PR with proper tests. |
This is the same as |
I fixed the issue and also found some more member functions that could have triggered the assertion, see #2866. Feedback welcome! |
@nlohmann Do you also need to track capacity in the external
? I'm getting a very hard to reproduce write access violation with Thrown here: One stack up: Edit: It's actually an array of |
What is the issue you have?
The assertion checking parent correctness in
assert_invariants()
fails for arrays when usingJSON_DIAGNOSTICS
. It seems parents of objects being inserted into arrays are not being updated.Please describe the steps to reproduce the issue.
To reproduce compile and run the following:
This produces the following assertion failure:
Note that this does not happen when there is only one
push_back
, i.e. only a single element in the array.This seems to have been the case since
JSON_DIAGNOSTICS
was introduced in 176d8e2.Can you provide a small but working code example?
Disabling
JSON_DIAGNOSTICS
or commenting out thepush_back
lines will make this code run.What is the expected behavior?
Assertion failure due to incorrect parents.
And what is the actual behavior instead?
No assert should fail and parents should be correct.
Which compiler and operating system are you using?
Which version of the library did you use?
develop
branchIf you experience a compilation error: can you compile and run the unit tests?
The text was updated successfully, but these errors were encountered: