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

Should WString use memcpy not strcpy #213

Open
petejan opened this issue Feb 25, 2017 · 2 comments
Open

Should WString use memcpy not strcpy #213

petejan opened this issue Feb 25, 2017 · 2 comments

Comments

@petejan
Copy link

petejan commented Feb 25, 2017

In WString.cpp (this also applies to avr core)

https://github.com/arduino/ArduinoCore-samd/blob/master/cores/arduino/WString.cpp#L179 and
https://github.com/arduino/ArduinoCore-samd/blob/master/cores/arduino/WString.cpp#L271

strcpy is used, where are length is passed to the copy and concat operation, whereas memcpy should be used so the char* can contain the 0 character.

@Reneg973
Copy link

Reneg973 commented Apr 7, 2021

Well AFAIK we talk about null terminated strings? So why should a null in this case not terminate it?
Of course there are sometimes strings, which are split by a "\0" and finalized by a "\0\0". In this case String is not the correct object to handle it.

@matthijskooijman matthijskooijman changed the title Should WString use memcpy not stycpy Should WString use memcpy not strcpy Apr 7, 2021
@matthijskooijman
Copy link
Collaborator

Usually, strings will be NUL-terminated, but the String class already stores an explicit length and supports passing a length to some methods and constructors, which means it should be able to support strings with embedded NUL characters too. Note that the String class is now developed as part of the ArdunoCore-API repo, so this issue should probably be discussed there. Some changes wrt to supporting strings with NUL have been made already in arduino/ArduinoCore-API#97, and some remaining issues are tracked in https://github.com/arduino/ArduinoCore-API/issue/111 https://github.com/arduino/ArduinoCore-API/issue/112 (though those are probably not all issues, maybe a container "support strings with embedded NUL" issue would make sense).

Maybe this issue could be closed in favor of the existing (or a new) issues in the -API repo?

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

3 participants