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:
parent
ff74813d54
commit
9c846bd52e
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user