Skip to content

Commit f17fc05

Browse files
committed
Make JSON_STRING_SIZE(N) return N+1 to fix third-party code
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
1 parent 04ac53d commit f17fc05

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
ArduinoJson: change log
22
=======================
33

4+
HEAD
5+
----
6+
7+
* Make `JSON_STRING_SIZE(N)` return `N+1` to fix third-party code (issue #2054)
8+
49
v7.0.3 (2024-02-05)
510
------
611

extras/tests/Deprecated/macros.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ TEST_CASE("JSON_OBJECT_SIZE") {
1414
}
1515

1616
TEST_CASE("JSON_STRING_SIZE") {
17-
REQUIRE(JSON_STRING_SIZE(10) == ArduinoJson::detail::sizeofString(10));
17+
REQUIRE(JSON_STRING_SIZE(10) == 11); // issue #2054
1818
}

src/ArduinoJson/compatibility.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#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))
4040

4141
// DEPRECATED: you don't need to compute the size anymore
42-
#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))
42+
#define JSON_STRING_SIZE(N) _Pragma ("GCC warning \"JSON_STRING_SIZE is deprecated, you don't need to compute the size anymore\"") (N+1)
4343

4444
#else
4545

@@ -50,7 +50,7 @@
5050
#define JSON_OBJECT_SIZE(N) (ArduinoJson::detail::sizeofObject(N))
5151

5252
// DEPRECATED: you don't need to compute the size anymore
53-
#define JSON_STRING_SIZE(N) (ArduinoJson::detail::sizeofString(N))
53+
#define JSON_STRING_SIZE(N) (N+1)
5454

5555
#endif
5656

0 commit comments

Comments
 (0)