Skip to content

Commit f6e12eb

Browse files
a1extSuGliderVojtechBartoska
authored
fix(core): fixed String::lastIndexOf bug (#9003)
Co-authored-by: Rodrigo Garcia <[email protected]> Co-authored-by: Vojtěch Bartoška <[email protected]>
1 parent 812a59a commit f6e12eb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Diff for: cores/esp32/WString.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,10 @@ int String::lastIndexOf(char ch, unsigned int fromIndex) const {
677677
wbuffer()[fromIndex + 1] = tempchar;
678678
if(temp == NULL)
679679
return -1;
680-
return temp - buffer();
680+
const int rv = temp - buffer();
681+
if(rv >= len())
682+
return -1;
683+
return rv;
681684
}
682685

683686
int String::lastIndexOf(const String &s2) const {

0 commit comments

Comments
 (0)