From f6e12eb7e900fd6484e186b4b681f5b9504d2e85 Mon Sep 17 00:00:00 2001 From: a1ext Date: Wed, 20 Dec 2023 15:54:04 +0100 Subject: [PATCH] fix(core): fixed String::lastIndexOf bug (#9003) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rodrigo Garcia Co-authored-by: Vojtěch Bartoška <76958047+VojtechBartoska@users.noreply.github.com> --- 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 6f0a4fc68..990a2824a 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 {