Skip to content

Commit

Permalink
Make JSON_STRING_SIZE(N) return N+1 to fix third-party code
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bblanchon committed Feb 18, 2024
1 parent 04ac53d commit f17fc05
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
------

Expand Down
2 changes: 1 addition & 1 deletion extras/tests/Deprecated/macros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions src/ArduinoJson/compatibility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit f17fc05

Please sign in to comment.