-
Notifications
You must be signed in to change notification settings - Fork 13.3k
use memcpy instead of strcpy in WString.cpp #6027
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
Conversation
I can happen String carries binary data, this simple update allows it. Also, memcpy is more efficient than strcpy when size is known. It's an harmless temporary fix until Webserver's painful arg("plain") can be worked out.
SSO uses It would be possible to rewrite SSO using the byte (sizeof(String)-1) as length, and adjusting the maximum SSO string size by 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixes needed per @earlephilhower for SSO case
Also, random thought: |
I may have encountered some issues where the string is empty. In the past this did not seem to cause any issues, but it seems that the switch to memmove is causing problems. Haven't had time to check the underlying code and to do full analysis, but can you please include testing the String length, before starting any memmove operation? An example: I just figured out that on 2.5.2 the replace function is not behaving as it was in the past. That is: it leads to a crash, and I suspect that it is due to the string being empty (or perhaps when there is nothing to replace in a valid string?). With the 'old' replace function this didn't happen. I'm sorry that I'm not able to provide any further details or sample code right now, but just wanted to contribute my two cents. |
This patch isn't applied yet, and memmove handles all cases memcpy would, just ensuring data integrity. If you can find a case that crashes that shouldn't in the current release, @KlaasjanN, we would really appreciate an issue on it. My own quick testing doesn't show any problems with empty strings:
Gives
and no crashes. |
Supercedes esp8266#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).
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.
I can happen String carries binary data, this simple update allows it.
Also,
memcpy
is more efficient thanstrcpy
when size is known.It's an harmless temporary fix until Webserver's painful
arg("plain")
can be worked out.@LaborEtArs