Skip to content

Commit

Permalink
Fix crash when using String::move on empty string (espressif#10938)
Browse files Browse the repository at this point in the history
  • Loading branch information
TD-er authored Feb 6, 2025
1 parent 6fcaf69 commit d33b221
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions cores/esp32/WString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,15 @@ String &String::copy(const char *cstr, unsigned int length) {
#ifdef __GXX_EXPERIMENTAL_CXX0X__
void String::move(String &rhs) {
if (buffer()) {
if (capacity() >= rhs.len()) {
if (capacity() >= rhs.len() && rhs.len() && rhs.buffer()) {
memmove(wbuffer(), rhs.buffer(), rhs.length() + 1);
setLen(rhs.len());
rhs.invalidate();
return;
} else {
if (!isSSO()) {
free(wbuffer());
setBuffer(nullptr);
}
}
if (!isSSO()) {
free(wbuffer());
setBuffer(nullptr);
}
}
if (rhs.isSSO()) {
Expand All @@ -259,10 +258,7 @@ void String::move(String &rhs) {
}
setCapacity(rhs.capacity());
setLen(rhs.len());
rhs.setSSO(false);
rhs.setCapacity(0);
rhs.setBuffer(nullptr);
rhs.setLen(0);
rhs.init();
}
#endif

Expand Down

0 comments on commit d33b221

Please sign in to comment.