fix(core): fixed String::lastIndexOf bug (#9003)

Co-authored-by: Rodrigo Garcia <rodrigo.garcia@espressif.com>
Co-authored-by: Vojtěch Bartoška <76958047+VojtechBartoska@users.noreply.github.com>
This commit is contained in:
a1ext 2023-12-20 15:54:04 +01:00 committed by GitHub
parent 812a59aadd
commit f6e12eb7e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -677,7 +677,10 @@ int String::lastIndexOf(char ch, unsigned int fromIndex) const {
wbuffer()[fromIndex + 1] = tempchar;
if(temp == NULL)
return -1;
return temp - buffer();
const int rv = temp - buffer();
if(rv >= len())
return -1;
return rv;
}
int String::lastIndexOf(const String &s2) const {