From 9c846bd52eed100d06de5f23c121011328575c11 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Thu, 26 Jul 2018 09:07:28 -0700 Subject: [PATCH] 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. --- cores/esp8266/WString.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cores/esp8266/WString.cpp b/cores/esp8266/WString.cpp index 9130d1bc1..edc8ab8b5 100644 --- a/cores/esp8266/WString.cpp +++ b/cores/esp8266/WString.cpp @@ -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);