fix(esp32): Fix appending to Strings longer than 64k (#11523)
If oldLen is truncated to uint16_t, appending to a String that is longer than 65535 bytes will create a broken string.
This commit is contained in:
parent
6754b1962c
commit
6476260e8f
1 changed files with 3 additions and 3 deletions
|
|
@ -180,7 +180,7 @@ bool String::changeBuffer(unsigned int maxStrLen) {
|
||||||
if (maxStrLen < sizeof(sso.buff) - 1) {
|
if (maxStrLen < sizeof(sso.buff) - 1) {
|
||||||
if (isSSO() || !buffer()) {
|
if (isSSO() || !buffer()) {
|
||||||
// Already using SSO, nothing to do
|
// Already using SSO, nothing to do
|
||||||
uint16_t oldLen = len();
|
size_t oldLen = len();
|
||||||
setSSO(true);
|
setSSO(true);
|
||||||
setLen(oldLen);
|
setLen(oldLen);
|
||||||
} else { // if bufptr && !isSSO()
|
} else { // if bufptr && !isSSO()
|
||||||
|
|
@ -188,7 +188,7 @@ bool String::changeBuffer(unsigned int maxStrLen) {
|
||||||
char temp[sizeof(sso.buff)];
|
char temp[sizeof(sso.buff)];
|
||||||
memcpy(temp, buffer(), maxStrLen);
|
memcpy(temp, buffer(), maxStrLen);
|
||||||
free(wbuffer());
|
free(wbuffer());
|
||||||
uint16_t oldLen = len();
|
size_t oldLen = len();
|
||||||
setSSO(true);
|
setSSO(true);
|
||||||
memcpy(wbuffer(), temp, maxStrLen);
|
memcpy(wbuffer(), temp, maxStrLen);
|
||||||
setLen(oldLen);
|
setLen(oldLen);
|
||||||
|
|
@ -201,7 +201,7 @@ bool String::changeBuffer(unsigned int maxStrLen) {
|
||||||
if (newSize > CAPACITY_MAX) {
|
if (newSize > CAPACITY_MAX) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
uint16_t oldLen = len();
|
size_t oldLen = len();
|
||||||
char *newbuffer = (char *)realloc(isSSO() ? nullptr : wbuffer(), newSize);
|
char *newbuffer = (char *)realloc(isSSO() ? nullptr : wbuffer(), newSize);
|
||||||
if (newbuffer) {
|
if (newbuffer) {
|
||||||
size_t oldSize = capacity() + 1; // include NULL.
|
size_t oldSize = capacity() + 1; // include NULL.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue