From af0edecddb8588190f2adbc410a1c940bd619ac4 Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Sat, 22 Feb 2020 12:06:39 +0100 Subject: [PATCH] Fixed MemberProxy::set(char[]) not duplicating the string (fixes #1191) --- CHANGELOG.md | 1 + extras/tests/ElementProxy/add.cpp | 8 ++++++++ extras/tests/ElementProxy/set.cpp | 8 ++++++++ extras/tests/MemberProxy/set.cpp | 8 ++++++++ src/ArduinoJson/Object/MemberProxy.hpp | 5 ++--- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04ecfcd8..0cb2707c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ HEAD * Added example `JsonFilterExample.ino` * Changed the array subscript operator to automatically add missing elements * Fixed "deprecated-copy" warning on GCC 9 (fixes #1184) +* Fixed `MemberProxy::set(char[])` not duplicating the string (issue #1191) v6.14.1 (2020-01-27) ------- diff --git a/extras/tests/ElementProxy/add.cpp b/extras/tests/ElementProxy/add.cpp index 93996a75..705b3e18 100644 --- a/extras/tests/ElementProxy/add.cpp +++ b/extras/tests/ElementProxy/add.cpp @@ -23,4 +23,12 @@ TEST_CASE("ElementProxy::add()") { REQUIRE(doc.as() == "[[\"world\"]]"); } + + SECTION("set(char[])") { + char s[] = "world"; + ep.add(s); + strcpy(s, "!!!!!"); + + REQUIRE(doc.as() == "[[\"world\"]]"); + } } diff --git a/extras/tests/ElementProxy/set.cpp b/extras/tests/ElementProxy/set.cpp index f597f1d3..bb99e15d 100644 --- a/extras/tests/ElementProxy/set.cpp +++ b/extras/tests/ElementProxy/set.cpp @@ -22,4 +22,12 @@ TEST_CASE("ElementProxy::set()") { REQUIRE(doc.as() == "[\"world\"]"); } + + SECTION("set(char[])") { + char s[] = "world"; + ep.set(s); + strcpy(s, "!!!!!"); + + REQUIRE(doc.as() == "[\"world\"]"); + } } diff --git a/extras/tests/MemberProxy/set.cpp b/extras/tests/MemberProxy/set.cpp index 3f27ee2e..467361e4 100644 --- a/extras/tests/MemberProxy/set.cpp +++ b/extras/tests/MemberProxy/set.cpp @@ -22,4 +22,12 @@ TEST_CASE("MemberProxy::set()") { REQUIRE(doc.as() == "{\"hello\":\"world\"}"); } + + SECTION("set(char[])") { // issue #1191 + char s[] = "world"; + mp.set(s); + strcpy(s, "!!!!!"); + + REQUIRE(doc.as() == "{\"hello\":\"world\"}"); + } } diff --git a/src/ArduinoJson/Object/MemberProxy.hpp b/src/ArduinoJson/Object/MemberProxy.hpp index b4cfce4c..926a1e76 100644 --- a/src/ArduinoJson/Object/MemberProxy.hpp +++ b/src/ArduinoJson/Object/MemberProxy.hpp @@ -107,8 +107,7 @@ class MemberProxy : public VariantOperators >, } template - FORCE_INLINE typename enable_if::value, bool>::type set( - const TValue &value) { + FORCE_INLINE bool set(const TValue &value) { return getOrAddUpstreamMember().set(value); } @@ -116,7 +115,7 @@ class MemberProxy : public VariantOperators >, // set(const char*) const // set(const __FlashStringHelper*) const template - FORCE_INLINE bool set(const TChar *value) { + FORCE_INLINE bool set(TChar *value) { return getOrAddUpstreamMember().set(value); }