-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
String::substring deferences NULL if the returned value is the empty string. This is due to a bug in String::move #148
Comments
Thanks or your report! Development of this code happens in https://github.com/arduino/ArduinoCore-API now, so I think issue can be moved there. @per1234, I see you also looked at this issue, did you decide not to move it for some reason? @MarkTillotson, there is already a pending PR to fix the move constructor to really do a move, see #21. I suspect that that might actually fix your issue as well, could you have a look at that to check? |
@matthijskooijman I agree that it should be moved to |
Ah, that explains. Apparently I do, so I moved the issue :-) |
Yes, that both fixes it and the code for move() looks much cleaner. I think this report can be marked as addressed by that PR... |
Thanks for confirming, I've marked this issue as fixed by the PR. |
In certain situations using the result of the String::substring() method will (read) deference NULL.
On some architectures this crashes the processor (Notable Teensy4)
[ using Arduino 1.8.13 / Teensyduino 1.53 - but the code in WString.cpp doesn't seem to have changed
for a long time ]
Necessary conditions:
substring() returns a null String
an existing non-null String is overwritten by this result.
The fault is that the String::move method in these circumstances calls strcpy with the source argument
as NULL.
You can see the bug report on the Teensy forum here: https://forum.pjrc.com/threads/67275-Issue-with-returning-zero-length-string-from-String-substring()
Example code to reproduce on Teensy4 (and presumably other architectures where address 0 faults if
deferenced):
Expected result:
What happens instead:
and the system hangs/crashes.
The definition of String::move I have:
Suggested fix:
The text was updated successfully, but these errors were encountered: