Detect string length overflows

This commit is contained in:
Benoit Blanchon
2023-10-09 11:58:02 +02:00
parent 9b34069a3b
commit 6fe4b9c01d
5 changed files with 67 additions and 6 deletions

View File

@ -80,4 +80,16 @@ TEST_CASE("JsonDocument::overflowed()") {
doc.shrinkToFit();
CHECK(doc.overflowed() == true);
}
SECTION("returns false when string length doesn't overflow") {
auto maxLength = ArduinoJson::detail::StringNode::maxLength;
CHECK(doc.set(std::string(maxLength, 'a')) == true);
CHECK(doc.overflowed() == false);
}
SECTION("returns true when string length overflows") {
auto maxLength = ArduinoJson::detail::StringNode::maxLength;
CHECK(doc.set(std::string(maxLength + 1, 'a')) == false);
CHECK(doc.overflowed() == true);
}
}