Fixed MemberProxy::set(char[]) not duplicating the string (fixes #1191)

This commit is contained in:
Benoit Blanchon
2020-02-22 12:06:39 +01:00
parent 300323cfd7
commit af0edecddb
5 changed files with 27 additions and 3 deletions

View File

@ -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)
-------

View File

@ -23,4 +23,12 @@ TEST_CASE("ElementProxy::add()") {
REQUIRE(doc.as<std::string>() == "[[\"world\"]]");
}
SECTION("set(char[])") {
char s[] = "world";
ep.add(s);
strcpy(s, "!!!!!");
REQUIRE(doc.as<std::string>() == "[[\"world\"]]");
}
}

View File

@ -22,4 +22,12 @@ TEST_CASE("ElementProxy::set()") {
REQUIRE(doc.as<std::string>() == "[\"world\"]");
}
SECTION("set(char[])") {
char s[] = "world";
ep.set(s);
strcpy(s, "!!!!!");
REQUIRE(doc.as<std::string>() == "[\"world\"]");
}
}

View File

@ -22,4 +22,12 @@ TEST_CASE("MemberProxy::set()") {
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}");
}
SECTION("set(char[])") { // issue #1191
char s[] = "world";
mp.set(s);
strcpy(s, "!!!!!");
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\"}");
}
}

View File

@ -107,8 +107,7 @@ class MemberProxy : public VariantOperators<MemberProxy<TObject, TStringRef> >,
}
template <typename TValue>
FORCE_INLINE typename enable_if<!is_array<TValue>::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<MemberProxy<TObject, TStringRef> >,
// set(const char*) const
// set(const __FlashStringHelper*) const
template <typename TChar>
FORCE_INLINE bool set(const TChar *value) {
FORCE_INLINE bool set(TChar *value) {
return getOrAddUpstreamMember().set(value);
}