-
Notifications
You must be signed in to change notification settings - Fork 7.4k
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
Fixed the String::lastIndexOf bug #9003
Conversation
👋 Hello a1ext, we appreciate your contribution to this project! Click to see more instructions ...
Review and merge process you can expect ...
|
c18f681
to
a73be69
Compare
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.
LGTM
The
String::lastIndexOf
incorrectly finds character\0
behind the string size, so extra check was added.Description of Change
This pull request fixes the bug in
int String::lastIndexOf(char ch, unsigned int fromIndex) const
function. The bug itselfis that if the character we are searching is
\0
this function returns an index behind bounds of the string itself.For example the following code prints that it found it at 4th position (points after the end of the actual string):
output:
but it must be
-1
because there is no\0
character inside the string itself.Tests scenarios
I've tested the code on M5Stack-CoreS3 hardware, Arduino-esp32 core v
3.20011.230801
(framework-arduinoespressif32)Test case when it is fixed: