Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use strncpy() in String::remove() #295

Closed
bmcdonnell opened this issue Apr 28, 2021 · 1 comment
Closed

Don't use strncpy() in String::remove() #295

bmcdonnell opened this issue Apr 28, 2021 · 1 comment

Comments

@bmcdonnell
Copy link

In WString.cpp, String::remove() should not use strncpy(), since its behavior is undefined when the source and destination overlap.

Sources:

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);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@hathach
Copy link
Member

hathach commented Apr 29, 2021

already fixed by #289 thanks for the issue.

@hathach hathach closed this as completed Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants