From f17fc055d3c6b36104b77789de6e0d809b289194 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sun, 18 Feb 2024 19:58:22 +0100 Subject: [PATCH] Make `JSON_STRING_SIZE(N)` return `N+1` to fix third-party code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ThingsBoard uses this macro to compute size of char arrays ಠ_ಠ https://github.com/thingsboard/thingsboard-client-sdk/blob/v0.12.2/src/Helper.h#L38 Closes #2054 --- CHANGELOG.md | 5 +++++ extras/tests/Deprecated/macros.cpp | 2 +- src/ArduinoJson/compatibility.hpp | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa4cfe6f..9362a245 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ ArduinoJson: change log ======================= +HEAD +---- + +* Make `JSON_STRING_SIZE(N)` return `N+1` to fix third-party code (issue #2054) + v7.0.3 (2024-02-05) ------ diff --git a/extras/tests/Deprecated/macros.cpp b/extras/tests/Deprecated/macros.cpp index 9db8f15a..36610c7d 100644 --- a/extras/tests/Deprecated/macros.cpp +++ b/extras/tests/Deprecated/macros.cpp @@ -14,5 +14,5 @@ TEST_CASE("JSON_OBJECT_SIZE") { } TEST_CASE("JSON_STRING_SIZE") { - REQUIRE(JSON_STRING_SIZE(10) == ArduinoJson::detail::sizeofString(10)); + REQUIRE(JSON_STRING_SIZE(10) == 11); // issue #2054 } diff --git a/src/ArduinoJson/compatibility.hpp b/src/ArduinoJson/compatibility.hpp index 26be5e72..6b99c424 100644 --- a/src/ArduinoJson/compatibility.hpp +++ b/src/ArduinoJson/compatibility.hpp @@ -39,7 +39,7 @@ #define JSON_OBJECT_SIZE(N) _Pragma ("GCC warning \"JSON_OBJECT_SIZE is deprecated, you don't need to compute the size anymore\"") (ArduinoJson::detail::sizeofObject(N)) // DEPRECATED: you don't need to compute the size anymore -#define JSON_STRING_SIZE(N) _Pragma ("GCC warning \"JSON_STRING_SIZE is deprecated, you don't need to compute the size anymore\"") (ArduinoJson::detail::sizeofString(N)) +#define JSON_STRING_SIZE(N) _Pragma ("GCC warning \"JSON_STRING_SIZE is deprecated, you don't need to compute the size anymore\"") (N+1) #else @@ -50,7 +50,7 @@ #define JSON_OBJECT_SIZE(N) (ArduinoJson::detail::sizeofObject(N)) // DEPRECATED: you don't need to compute the size anymore -#define JSON_STRING_SIZE(N) (ArduinoJson::detail::sizeofString(N)) +#define JSON_STRING_SIZE(N) (N+1) #endif