1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-25 20:02:37 +03:00
Earle F. Philhower, III 54240d2cc5
Fix String::replace() garbage at end of string (#5897)
* Fix String::replace() 

Fixes #5883 and supercedes #5890

The replace() function was using len() while in the middle of buffer
operations.  In SSO mode len() is not stored separately and is a call to
strlen(), which may not be legal if you're in the middle of overwriting
the SSO buffer, as was the case in ::replace when the replacement string
was longer than the find string.  This caused potential garbage at the
end of the string when accessed.  Instead, just cache the length in a
local while doing the operation.

Add in test cases from #5890 as well as some new ones that fail on the
unmodified core.

* Fix stack smashing error on 64b

When pointers are 8 bytes long, the size of a String is larger than 16
chars.  Increase the allocated array we're using in the test to avoid a
"stack smashing" error.

* Manually call destructor in test

Just for clarity, manually call the destructor for the Strings() that
are "placement new'd" in the String tests.  It is a no-op for the
existing test, since thanks to SSO there are no memory allocations, but
will help in case someone adds tests later which include longer strings.
2019-03-20 06:18:04 -07:00
..
2019-03-07 11:37:38 +01:00
2019-03-14 11:19:21 +01:00
2019-03-14 11:19:21 +01:00
2019-02-06 23:06:17 -03:00
2018-11-24 02:00:34 -03:00
2017-05-12 01:03:14 -05:00
2019-02-06 23:06:17 -03:00
2016-03-03 02:13:22 +03:00
2019-02-06 23:06:17 -03:00
2019-02-06 23:06:17 -03:00
2018-12-10 10:35:11 -03:00
2014-12-01 00:34:28 +03:00
2019-02-08 17:37:43 +00:00