Skip to content

Commit

Permalink
fix: enforce switch & pot ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelcoeffic committed Oct 14, 2023
1 parent 6db0e72 commit 5b668ff
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion radio/src/gui/gui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down

0 comments on commit 5b668ff

Please sign in to comment.