1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-21 10:26:06 +03:00

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.
This commit is contained in:
Earle F. Philhower, III 2018-07-26 09:07:28 -07:00 committed by GitHub
parent ff74813d54
commit 9c846bd52e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -270,8 +270,9 @@ unsigned char String::concat(const String &s) {
return 1;
if (!reserve(newlen))
return 0;
memcpy(s.buffer + len, s.buffer, len);
memcpy(buffer + len, buffer, len);
len = newlen;
buffer[len] = 0;
return 1;
} else {
return concat(s.buffer, s.len);