From a73be69e1c21dabd0b0a069523698e723ac185c2 Mon Sep 17 00:00:00 2001 From: a1ext Date: Fri, 15 Dec 2023 02:18:30 +0300 Subject: [PATCH] fix(core): fixed String::lastIndexOf bug --- cores/esp32/WString.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cores/esp32/WString.cpp b/cores/esp32/WString.cpp index 6f0a4fc68a8..990a2824a51 100644 --- a/cores/esp32/WString.cpp +++ b/cores/esp32/WString.cpp @@ -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 {