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.
* 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
* 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.
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.
* 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
* 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.