From a49c1701936a6ba5d56af99db97bcfd1e00555c0 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 16 Oct 2023 10:40:38 +0200 Subject: [PATCH] fix: Enforce switch & pot ranges (#4204) --- radio/src/gui/gui_common.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/radio/src/gui/gui_common.cpp b/radio/src/gui/gui_common.cpp index 4ef6f8b2a..5f784b6a4 100644 --- a/radio/src/gui/gui_common.cpp +++ b/radio/src/gui/gui_common.cpp @@ -368,6 +368,10 @@ bool isSwitchAvailable(int swtch, SwitchContext context) if (swtch >= SWSRC_FIRST_SWITCH && swtch <= SWSRC_LAST_SWITCH) { div_t swinfo = switchInfo(swtch); + if (swinfo.quot >= switchGetMaxSwitches() + switchGetMaxFctSwitches()) { + return false; + } + if (!SWITCH_EXISTS(swinfo.quot)) { return false; } @@ -387,7 +391,7 @@ bool isSwitchAvailable(int swtch, SwitchContext context) if (swtch >= SWSRC_FIRST_MULTIPOS_SWITCH && swtch <= SWSRC_LAST_MULTIPOS_SWITCH) { int index = (swtch - SWSRC_FIRST_MULTIPOS_SWITCH) / XPOTS_MULTIPOS_COUNT; - return IS_POT_MULTIPOS(index); + return (index < adcGetMaxInputs(ADC_INPUT_POT)) ? IS_POT_MULTIPOS(index) : false; } if (swtch >= SWSRC_FIRST_TRIM && swtch <= SWSRC_LAST_TRIM) {