Skip to content

Commit

Permalink
Fix concat not 0-terminating when String shrunk
Browse files Browse the repository at this point in the history
As @devyte noticed, PR esp8266#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.
  • Loading branch information
earlephilhower committed Jul 26, 2018
1 parent ff74813 commit c530efe
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cores/esp8266/WString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c530efe

Please sign in to comment.