From e487273ce91785300c55997d1fb4c3bc70a281e7 Mon Sep 17 00:00:00 2001 From: WismyYao Date: Mon, 2 Aug 2021 15:58:14 +0800 Subject: [PATCH] Fix the out of bounds of array --- radio/src/thirdparty/libopenui/src/textedit.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/textedit.cpp b/radio/src/thirdparty/libopenui/src/textedit.cpp index 3edcfaafb..8f3a8ba08 100644 --- a/radio/src/thirdparty/libopenui/src/textedit.cpp +++ b/radio/src/thirdparty/libopenui/src/textedit.cpp @@ -209,13 +209,15 @@ void TextEdit::onEvent(event_t event) break; case EVT_KEY_BREAK(KEY_PGDN): - memmove(&value[cursorPos], &value[cursorPos + 1], length - cursorPos - 1); - value[length - 1] = '\0'; - changed = true; - if (cursorPos > 0 && value[cursorPos] == '\0') { - cursorPos = cursorPos - 1; + if (cursorPos < length) { + memmove(&value[cursorPos], &value[cursorPos + 1], length - cursorPos - 1); + value[length - 1] = '\0'; + changed = true; + if (cursorPos > 0 && value[cursorPos] == '\0') { + cursorPos = cursorPos - 1; + } + invalidate(); } - invalidate(); break; }