1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

StreamString SSO bug (#6035)

With SSO implementation in String, StreamString::write generates wrong strings under some circumstances.
Reason is that String::len() returns strlen(sso_buf) if SSO=true but with newly written data (in StreamString::write) the null-termination missing at the time len() is called.
Furthermore, len() is called twice which is inefficient if SSO=true.

* Git ignore

* - StreamString fix

* Remove changes to gitignore

* Fix missing space for 0-terminator lost in conversion
This commit is contained in:
Harald 2019-05-02 18:55:43 +02:00 committed by Earle F. Philhower, III
parent 106d6f33a0
commit a994b75d75

View File

@ -25,10 +25,11 @@
size_t StreamString::write(const uint8_t *data, size_t size) { size_t StreamString::write(const uint8_t *data, size_t size) {
if(size && data) { if(size && data) {
if(reserve(length() + size + 1)) { const unsigned int newlen = length() + size;
if(reserve(newlen + 1)) {
memcpy((void *) (wbuffer() + len()), (const void *) data, size); memcpy((void *) (wbuffer() + len()), (const void *) data, size);
setLen(len() + size); setLen(newlen);
*(wbuffer() + len()) = 0x00; // add null for string end *(wbuffer() + newlen) = 0x00; // add null for string end
return size; return size;
} }
} }