Skip to content

Commit f051f83

Browse files
committed
Undef true and false macros
Replacing `true` with `1` changes `JsonString("ABC", true)` into `JsonString("ABC", 1)`, so all static strings had a length of 1. This is a workaround for arduino/ArduinoCore-sam#50 Fixes #2181
1 parent 411424b commit f051f83

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
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+
* Fix truncated strings on Arduino Due (issue #2181)
8+
49
v7.4.1 (2025-04-11)
510
------
611

extras/tests/Misc/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,23 @@ set_tests_properties(Misc
2929
PROPERTIES
3030
LABELS "Catch"
3131
)
32+
33+
add_executable(Issue2181
34+
issue2181.cpp # Cannot be linked with other tests
35+
)
36+
37+
set_target_properties(Issue2181 PROPERTIES UNITY_BUILD OFF)
38+
39+
add_test(Issue2181 Issue2181)
40+
41+
set_tests_properties(Issue2181
42+
PROPERTIES
43+
LABELS "Catch"
44+
)
45+
46+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
47+
target_compile_options(Issue2181
48+
PRIVATE
49+
-Wno-keyword-macro # keyword is hidden by macro definition
50+
)
51+
endif()

extras/tests/Misc/issue2181.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// ArduinoJson - https://arduinojson.org
2+
// Copyright © 2014-2025, Benoit BLANCHON
3+
// MIT License
4+
5+
#define true 0x1
6+
#define false 0x0
7+
8+
#include <ArduinoJson.h>
9+
#include <catch.hpp>
10+
11+
TEST_CASE("Issue #2181") {
12+
JsonDocument doc;
13+
doc["hello"] = "world";
14+
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}");
15+
}

src/ArduinoJson.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@
2626
# endif
2727
#endif
2828

29+
// Remove true and false macros defined by some cores, such as Arduino Due's
30+
// See issues #2181 and arduino/ArduinoCore-sam#50
31+
#ifdef true
32+
# undef true
33+
#endif
34+
#ifdef false
35+
# undef false
36+
#endif
37+
2938
#include "ArduinoJson/Array/JsonArray.hpp"
3039
#include "ArduinoJson/Object/JsonObject.hpp"
3140
#include "ArduinoJson/Variant/JsonVariantConst.hpp"

0 commit comments

Comments
 (0)