File tree Expand file tree Collapse file tree 4 files changed +8
-7
lines changed Expand file tree Collapse file tree 4 files changed +8
-7
lines changed Original file line number Diff line number Diff line change 55----
66
77* Changed the rules of string duplication (issue #658 )
8+ * Changed the return type of ` strdup() ` to ` const char* ` to prevent double duplication
89
910> ### New rules for string duplication
1011>
Original file line number Diff line number Diff line change @@ -38,19 +38,19 @@ class JsonBuffer : Internals::NonCopyable {
3838
3939 // Duplicates a string
4040 //
41- // char* strdup(TValue);
41+ // const char* strdup(TValue);
4242 // TValue = const std::string&, const String&,
4343 template <typename TString>
4444 typename TypeTraits::EnableIf<!TypeTraits::IsArray<TString>::value,
45- char *>::type
45+ const char *>::type
4646 strdup (const TString &src) {
4747 return Internals::StringTraits<TString>::duplicate (src, this );
4848 }
4949 //
50- // char* strdup(TValue);
50+ // const char* strdup(TValue);
5151 // TValue = const char*, const char[N], const FlashStringHelper*
5252 template <typename TString>
53- char *strdup (const TString *src) {
53+ const char *strdup (const TString *src) {
5454 return Internals::StringTraits<const TString *>::duplicate (src, this );
5555 }
5656
Original file line number Diff line number Diff line change @@ -10,14 +10,14 @@ TEST_CASE("DynamicJsonBuffer::strdup()") {
1010
1111 SECTION (" Should return a copy" ) {
1212 char original[] = " hello" ;
13- char * copy = buffer.strdup (original);
13+ const char * copy = buffer.strdup (original);
1414 strcpy (original, " world" );
1515 REQUIRE (std::string (" hello" ) == copy);
1616 }
1717
1818 SECTION (" Given NULL, return NULL" ) {
1919 const char * original = NULL ;
20- char * copy = buffer.strdup (original);
20+ const char * copy = buffer.strdup (original);
2121 REQUIRE (0 == copy);
2222 }
2323}
Original file line number Diff line number Diff line change @@ -243,7 +243,7 @@ TEST_CASE("std::string") {
243243
244244 SECTION (" JsonBuffer_strdup" ) {
245245 std::string original (" hello" );
246- char *copy = jb.strdup (original);
246+ const char *copy = jb.strdup (original);
247247 original[0 ] = ' w' ;
248248 REQUIRE (std::string (" hello" ) == copy);
249249 }
You can’t perform that action at this time.
0 commit comments