From 89dc1ae97f018a261d789d1120c4fa11fdb813a1 Mon Sep 17 00:00:00 2001 From: Soeren Moch Date: Sat, 18 Jun 2022 09:30:50 +0200 Subject: Avoid crash when selecting invisibile menu items Items can be selected with number key presses in main and setup menus. When the selected item is not visible (scrolled out of the visible range) there is no need to update the item before closing the menu. Check for this condition to avoid crashing. Signed-off-by: Soeren Moch --- displaymenu.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/displaymenu.c b/displaymenu.c index bcbd9ed..b83eae5 100644 --- a/displaymenu.c +++ b/displaymenu.c @@ -489,10 +489,15 @@ bool cNopacityDisplayMenu::SetItemRecording(const cRecording *Recording, int Ind return true; } - void cNopacityDisplayMenu::SetItem(const char *Text, int Index, bool Current, bool Selectable) { - bool hasIcons = false; - bool MainOrSetup = false; + if (Index < 0) + return; + if ((int)menuItems.size() <= Index) { + int maxitems = MaxItems(); + if (maxitems <= Index) + return; + menuItems.resize(maxitems); + } cString *strItems = new cString[MaxTabs]; int *tabItems = new int[2*MaxTabs]; for (int i=0; i