Skip to content

Commit

Permalink
Fix volatile bool serialized as 1 or 0
Browse files Browse the repository at this point in the history
Fixes #2029
  • Loading branch information
bblanchon committed Jan 10, 2024
1 parent 3e1be98 commit 5d1d272
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ HEAD
----

* Fix warning `function returns incomplete class type` on IAR (issue #2001)
* Fix `volatile bool` serialized as `1` or `0` instead of `true` or `false` (issue #2029)

v6.21.4 (2023-12-07)
-------
Expand Down
7 changes: 7 additions & 0 deletions extras/tests/JsonVariant/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ TEST_CASE("volatile") {
DynamicJsonDocument doc(4096);
JsonVariant variant = doc.to<JsonVariant>();

SECTION("volatile bool") { // issue #2029
volatile bool f = true;
variant.set(f);
CHECK(variant.is<bool>() == true);
CHECK(variant.as<bool>() == true);
}

SECTION("volatile int") {
volatile int f = 42;
variant.set(f);
Expand Down
3 changes: 2 additions & 1 deletion src/ArduinoJson/Variant/VariantImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ VariantRefBase<TDerived>::is() const {
template <typename TDerived>
template <typename T>
inline bool VariantRefBase<TDerived>::set(const T& value) const {
Converter<T>::toJson(value, getOrCreateVariant());
Converter<typename detail::remove_cv<T>::type>::toJson(value,
getOrCreateVariant());
MemoryPool* pool = getPool();
return pool && !pool->overflowed();
}
Expand Down

0 comments on commit 5d1d272

Please sign in to comment.