Fix String::clear() not clearing the string properly
Fixes: https://github.com/espressif/arduino-esp32/issues/4893
This commit is contained in:
parent
6e7cc5210d
commit
22a488cf23
@ -130,9 +130,9 @@ String::~String() {
|
||||
|
||||
inline void String::init(void) {
|
||||
setSSO(false);
|
||||
setBuffer(nullptr);
|
||||
setCapacity(0);
|
||||
setLen(0);
|
||||
setBuffer(nullptr);
|
||||
}
|
||||
|
||||
void String::invalidate(void) {
|
||||
|
@ -301,7 +301,17 @@ class String {
|
||||
inline unsigned int len() const { return isSSO() ? sso.len : ptr.len; }
|
||||
inline unsigned int capacity() const { return isSSO() ? (unsigned int)SSOSIZE - 1 : ptr.cap; } // Size of max string not including terminal NUL
|
||||
inline void setSSO(bool set) { sso.isSSO = set; }
|
||||
inline void setLen(int len) { if (isSSO()) sso.len = len; else ptr.len = len; }
|
||||
inline void setLen(int len) {
|
||||
if (isSSO()) {
|
||||
sso.len = len;
|
||||
sso.buff[len] = 0;
|
||||
} else {
|
||||
ptr.len = len;
|
||||
if (ptr.buff) {
|
||||
ptr.buff[len] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
inline void setCapacity(int cap) { if (!isSSO()) ptr.cap = cap; }
|
||||
inline void setBuffer(char *buff) { if (!isSSO()) ptr.buff = buff; }
|
||||
// Buffer accessor functions
|
||||
|
Loading…
Reference in New Issue
Block a user