Skip to content

Commit

Permalink
StreamString SSO bug (#6035)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mongozmaki authored and earlephilhower committed May 2, 2019
1 parent 106d6f3 commit a994b75
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions cores/esp8266/StreamString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@

size_t StreamString::write(const uint8_t *data, size_t size) {
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);
setLen(len() + size);
*(wbuffer() + len()) = 0x00; // add null for string end
setLen(newlen);
*(wbuffer() + newlen) = 0x00; // add null for string end
return size;
}
}
Expand Down

0 comments on commit a994b75

Please sign in to comment.