Skip to content

Commit 9c846bd

Browse files
Fix concat not 0-terminating when String shrunk (#4962)
As @devyte noticed, PR #4955 has an issue when you catenate a string to itself and the string used to hold a longer value because it does not explicitly 0-terminate the resulting string. If the string was extended, however, reserve() would 0-terminate by default. Always terminate the result of `s += s;` now.
1 parent ff74813 commit 9c846bd

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

cores/esp8266/WString.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,9 @@ unsigned char String::concat(const String &s) {
270270
return 1;
271271
if (!reserve(newlen))
272272
return 0;
273-
memcpy(s.buffer + len, s.buffer, len);
273+
memcpy(buffer + len, buffer, len);
274274
len = newlen;
275+
buffer[len] = 0;
275276
return 1;
276277
} else {
277278
return concat(s.buffer, s.len);

0 commit comments

Comments
 (0)