From 5ed1d63d6e950bb1fd3463229d439a8479134b82 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 22 Sep 2021 12:54:35 +0200 Subject: [PATCH] [choice] check boundaries when accessing values vector EdgeTX/edgetx#767 --- radio/src/thirdparty/libopenui/src/choice.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/choice.cpp b/radio/src/thirdparty/libopenui/src/choice.cpp index 0d935b245..536c19f05 100644 --- a/radio/src/thirdparty/libopenui/src/choice.cpp +++ b/radio/src/thirdparty/libopenui/src/choice.cpp @@ -104,9 +104,19 @@ void Choice::setValues(const char * const values[]) void Choice::paint(BitmapBuffer * dc) { FormField::paint(dc); - theme->drawChoice(dc, this, - textHandler ? textHandler(getValue()).c_str() - : values[getValue() - vmin].c_str()); + auto val = getValue(); + + const char* str = ""; + if (textHandler) { + str = textHandler(val).c_str(); + } else { + val -= vmin; + if (val > 0 && val < values.size()) { + values[val - vmin].c_str(); + } + } + + theme->drawChoice(dc, this, str); } #if defined(HARDWARE_KEYS)