Description
The ESP8266 Arduino port just discovered the following line in String::remove
where strncpy
is used with overlapping source and destination addresses (it's moving things backwards in the allocated buffer). See link for the valgrind warnings reported by our CI system.
ArduinoCore-avr/cores/arduino/WString.cpp
Lines 697 to 699 in b7c6076
str*cpy
is undefined when you overlap source and destination
While it's true that on the AVR, an 8-bit MCU, str*cpy will be implemented in a byte-wise manner, this code has and will probably be copied to 16- and 32-bit systems where they may use optimizations which give strange results occasionally due to the overlap. A simple replacement of the strcpy
with a memmove
in this line clears this error and provides desired behavior on all systems.