🥅 add assertion for invariant in SAX-DOM parser (#3498)

This commit is contained in:
Niels Lohmann 2022-05-19 19:56:33 +02:00 committed by GitHub
parent 93c9e0c703
commit 6ff2ea3aed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -233,6 +233,9 @@ class json_sax_dom_parser
bool key(string_t& val)
{
JSON_ASSERT(!ref_stack.empty());
JSON_ASSERT(ref_stack.back()->is_object());
// add null at given key and store the reference for later
object_element = &(ref_stack.back()->m_value.object->operator[](val));
return true;
@ -240,6 +243,9 @@ class json_sax_dom_parser
bool end_object()
{
JSON_ASSERT(!ref_stack.empty());
JSON_ASSERT(ref_stack.back()->is_object());
ref_stack.back()->set_parents();
ref_stack.pop_back();
return true;
@ -259,6 +265,9 @@ class json_sax_dom_parser
bool end_array()
{
JSON_ASSERT(!ref_stack.empty());
JSON_ASSERT(ref_stack.back()->is_array());
ref_stack.back()->set_parents();
ref_stack.pop_back();
return true;

View File

@ -6230,6 +6230,9 @@ class json_sax_dom_parser
bool key(string_t& val)
{
JSON_ASSERT(!ref_stack.empty());
JSON_ASSERT(ref_stack.back()->is_object());
// add null at given key and store the reference for later
object_element = &(ref_stack.back()->m_value.object->operator[](val));
return true;
@ -6237,6 +6240,9 @@ class json_sax_dom_parser
bool end_object()
{
JSON_ASSERT(!ref_stack.empty());
JSON_ASSERT(ref_stack.back()->is_object());
ref_stack.back()->set_parents();
ref_stack.pop_back();
return true;
@ -6256,6 +6262,9 @@ class json_sax_dom_parser
bool end_array()
{
JSON_ASSERT(!ref_stack.empty());
JSON_ASSERT(ref_stack.back()->is_array());
ref_stack.back()->set_parents();
ref_stack.pop_back();
return true;