Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions cores/esp32/WString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ bool String::changeBuffer(unsigned int maxStrLen) {
/*********************************************/

String &String::copy(const char *cstr, unsigned int length) {
if (!reserve(length)) {
if (cstr == nullptr || !reserve(length)) {
invalidate();
return *this;
}
memmove(wbuffer(), cstr, length + 1);
memmove(wbuffer(), cstr, length);
setLen(length);
return *this;
}
Expand Down Expand Up @@ -270,12 +270,7 @@ String &String::operator=(const String &rhs) {
if (this == &rhs) {
return *this;
}
if (rhs.buffer()) {
copy(rhs.buffer(), rhs.len());
} else {
invalidate();
}
return *this;
return copy(rhs.buffer(), rhs.len());
}

#ifdef __GXX_EXPERIMENTAL_CXX0X__
Expand All @@ -295,12 +290,7 @@ String &String::operator=(StringSumHelper &&rval) {
#endif

String &String::operator=(const char *cstr) {
if (cstr) {
copy(cstr, strlen(cstr));
} else {
invalidate();
}
return *this;
return copy(cstr, strlen(cstr));
}

/*********************************************/
Expand Down
Loading