diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp index 7c7021c63..23df9925c 100644 --- a/include/nlohmann/detail/input/json_sax.hpp +++ b/include/nlohmann/detail/input/json_sax.hpp @@ -749,6 +749,8 @@ class json_sax_dom_parser JSON_HEDLEY_NEVER_INLINE void grow() { + // the stack starts with local_capacity frames and only grows + JSON_ASSERT(capacity != 0); const std::size_t new_capacity = capacity * 2; std::unique_ptr new_heap(new frame[new_capacity]); // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) std::copy(data, data + count, new_heap.get()); @@ -914,6 +916,8 @@ class json_sax_dom_parser /// directly if the value was the one too many. void place_container(const frame& f, frame* enclosing, BasicJsonType&& value, const bool enclosing_is_innermost) { + // a container without a slot of its own is collected for an enclosing one + JSON_ASSERT(f.slot != nullptr || enclosing != nullptr); if (f.slot != nullptr) { *f.slot = std::move(value); diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 9a63b2360..1bfd56c43 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -16529,6 +16529,8 @@ class json_sax_dom_parser JSON_HEDLEY_NEVER_INLINE void grow() { + // the stack starts with local_capacity frames and only grows + JSON_ASSERT(capacity != 0); const std::size_t new_capacity = capacity * 2; std::unique_ptr new_heap(new frame[new_capacity]); // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) std::copy(data, data + count, new_heap.get()); @@ -16694,6 +16696,8 @@ class json_sax_dom_parser /// directly if the value was the one too many. void place_container(const frame& f, frame* enclosing, BasicJsonType&& value, const bool enclosing_is_innermost) { + // a container without a slot of its own is collected for an enclosing one + JSON_ASSERT(f.slot != nullptr || enclosing != nullptr); if (f.slot != nullptr) { *f.slot = std::move(value);