Skip to content

Commit 998ce4c

Browse files
authored
Allow String::concat(const String &s) with s.buffer() == nullptr
When constructing a String object, the internal buffer is a nullptr. However concatenating this to another String would return `false` while this is perfectly fine to do.
1 parent 3470796 commit 998ce4c

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

Diff for: cores/esp32/WString.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -311,23 +311,21 @@ bool String::concat(const String &s) {
311311
// Special case if we're concatting ourself (s += s;) since we may end up
312312
// realloc'ing the buffer and moving s.buffer in the method called
313313
if (&s == this) {
314-
unsigned int newlen = 2 * len();
315-
if (!s.buffer()) {
316-
return false;
317-
}
318314
if (s.len() == 0) {
319315
return true;
320316
}
317+
if (!s.buffer()) {
318+
return false;
319+
}
320+
unsigned int newlen = 2 * len();
321321
if (!reserve(newlen)) {
322322
return false;
323323
}
324324
memmove(wbuffer() + len(), buffer(), len());
325325
setLen(newlen);
326-
wbuffer()[len()] = 0;
327326
return true;
328-
} else {
329-
return concat(s.buffer(), s.len());
330327
}
328+
return concat(s.buffer(), s.len());
331329
}
332330

333331
bool String::concat(const char *cstr, unsigned int length) {

0 commit comments

Comments
 (0)