diff --git a/CHANGELOG.md b/CHANGELOG.md index f1cdeb09..f0ff97fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ ArduinoJson: change log ======================= +HEAD +---- + +* Fix crash when adding an object member in a too small `JsonDocument` + v6.19.0 (2022-01-08) ------- diff --git a/extras/tests/JsonDocument/overflowed.cpp b/extras/tests/JsonDocument/overflowed.cpp index f9bcb9e8..cea0db9d 100644 --- a/extras/tests/JsonDocument/overflowed.cpp +++ b/extras/tests/JsonDocument/overflowed.cpp @@ -35,6 +35,12 @@ TEST_CASE("JsonDocument::overflowed()") { CHECK(doc.overflowed() == false); } + SECTION("returns true after a failed member add") { + StaticJsonDocument<1> doc; + doc["example"] = true; + CHECK(doc.overflowed() == true); + } + SECTION("returns true after a failed deserialization") { StaticJsonDocument doc; deserializeJson(doc, "[\"example\"]"); diff --git a/src/ArduinoJson/Variant/SlotFunctions.hpp b/src/ArduinoJson/Variant/SlotFunctions.hpp index ca74dc1f..9119a460 100644 --- a/src/ArduinoJson/Variant/SlotFunctions.hpp +++ b/src/ArduinoJson/Variant/SlotFunctions.hpp @@ -26,6 +26,8 @@ struct SlotKeySetter { template inline bool slotSetKey(VariantSlot* var, TAdaptedString key, MemoryPool* pool, TStoragePolicy storage) { + if (!var) + return false; return storage.store(key, pool, SlotKeySetter(var)); }