Closed
Description
In WString.cpp
, String::remove()
should not use strncpy()
, since its behavior is undefined when the source and destination overlap.
Sources:
- https://en.cppreference.com/w/c/string/byte/strncpy (C)
- https://en.cppreference.com/w/cpp/string/byte/strncpy (C++)
I noticed the issue due to the compiler warning below.
C:\Users\username\AppData\Local\Arduino15\packages\adafruit\hardware\samd\1.6.7\cores\arduino\WString.cpp: In member function 'void String::remove(unsigned int, unsigned int)':
C:\Users\username\AppData\Local\Arduino15\packages\adafruit\hardware\samd\1.6.7\cores\arduino\WString.cpp:701:9: warning: 'char* strncpy(char*, const char*, size_t)' accessing 0 or more bytes at offsets [-1073741824, 1073741823] and [-1073741824, 1073741823] may overlap up to 4294967295 bytes at offset [5368709117, 1073741823] [-Wrestrict]
701 | strncpy(writeTo, buffer + index + count,len - index);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Metadata
Metadata
Assignees
Labels
No labels