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

8 Commits

Author SHA1 Message Date
Earle F. Philhower, III
0920daf251
Add some more CI tests for String::replace (#6193) 2019-06-10 12:51:43 -07:00
Earle F. Philhower, III
78a1a66e6d
Make SSO support \0s, use memmove, add test (#6155)
Supercedes #6027

Make SSO more generic by keeping track of its length explicitly,
allowing for embedded \0s to exist in the String (just like the non-SSO
ones).

Use memmove/memcpy_P when we know the length of a string to save CPU
time.

Add tests to inject \0s in a String to ensure it is still working as
designed.
2019-06-05 08:11:53 -07:00
Harald
a67aa569da Test for StreamString SSO bug (#6035) (#6041) 2019-05-03 07:09:32 -07:00
Earle F. Philhower, III
9712170276
Fix String.replace overlapping strcpy (#5966)
* Fix String.replace overlapping strcpy

Fixes #5949

Adds a test from the issue above and fixes the problem valgrind found.

Additional pathological memcpy->memmove fixes
2019-04-10 17:21:15 +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
Earle F. Philhower, III
7369133681
Small String Optimization (#5690)
Reduce String memory overhead from 24 bytes to 16 bytes by limiting the
maximum string length to <64Kbytes (which is larger than heap so no
effective problem).

Add Small String Optimization, SSO, which instead of allocating pointers
to small strings on the heap will store the string in place of the
pointer in the class.  This should reduce memory fragmentation as

Save up to 12 chars (11 + \0) in String itself by using the terminating
\0 in the inline string as a flag to identify if this is a SSO or a heap
string.

Add a host test that verifies that no memory is allocated until a
full 11 characters are assigned to a string, as well as checking all
intermediate values.

No user code changes should be required to work with this optimization.
2019-02-08 17:37:43 +00:00
Earle F. Philhower, III
6883beedec
Remove broken ltoa/ultoa, call itoa/utoa (#5625)
* Remove broken ltoa/ultoa, call itoa/utoa

Use the newlib integer-to-ASCII non-POSIX calls instead of rolling
our own.  Should be safe as sizeof(long) == sizeof(int).
The custom functions behaved differently from itoa when passed in
negative values in non-base-10.

Add host tests for negative non-base-10 int/longs
2019-01-17 02:08:19 +00:00
Earle F. Philhower, III
03ea61a32a Add valgrind and string tests to host_tests (#4939)
* Add valgrind and string tests to host_tests

Valgrind identified an error that was causing intermittent failures in
the host tests, and can check for subtle memory access and allocation bugs.
Add it to the standard host_test suite, and any errors will cause test
failure.

Also start adding string tests, since two undefined behaviors have been
found so far just by inspection.

* Add additional String tests

Looks like a possible bug in the concatenation operator, need to verify
expected behavior.

* Remove verbose from valgrind run

No need to be so chatty on the test.  Errors were a little hard to spot.
Go to normal verbosity.

* Add lcov and more string tests

LCOV and genhtml can generate nice HTML coverage charts hilighting test
coverage issues in a much simpler way than gcov text format.  Generate these
automatically from gcov output.

Add additional string creation and comparison tests.

* Move String coverage to >50%

Additional string tests and checks

* 66% test coverage in String

* Add allocation-unit-sized strings test

Ensure that strings that are right on the edge of the allocation
size are handled properly and account for trailing 0.
2018-07-27 13:10:55 -04:00