diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp index 5af853ac1..6fd0be52d 100644 --- a/include/nlohmann/detail/input/json_sax.hpp +++ b/include/nlohmann/detail/input/json_sax.hpp @@ -937,6 +937,8 @@ class json_sax_dom_parser : public json_sax_dom_error_state /// directly if the value was the one too many. void place_container(const frame& f, frame* enclosing, BasicJsonType&& value, const bool enclosing_is_innermost) { + // only a container with a slot may have no enclosing container + 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 b40405363..b2f432922 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -16043,6 +16043,8 @@ class json_sax_dom_parser : public json_sax_dom_error_state /// directly if the value was the one too many. void place_container(const frame& f, frame* enclosing, BasicJsonType&& value, const bool enclosing_is_innermost) { + // only a container with a slot may have no enclosing container + JSON_ASSERT(f.slot != nullptr || enclosing != nullptr); if (f.slot != nullptr) { *f.slot = std::move(value);