Skip to content

Commit

Permalink
fix(cpn): function switches induced crash
Browse files Browse the repository at this point in the history
  • Loading branch information
elecpower committed Oct 17, 2024
1 parent e8224b8 commit 44e5d26
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions companion/src/firmwares/boardjson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ int BoardJson::getInputTypeOffset(const InputsTable * inputs, Board::AnalogInput
return i;
}

return 0;
return -1;
}

const Board::InputInfo BoardJson::getInputInfo(int index) const
Expand Down Expand Up @@ -531,7 +531,7 @@ int BoardJson::getSwitchTypeOffset(const SwitchesTable * switches, Board::Switch
return i;
}

return 0;
return -1;
}

const int BoardJson::getSwitchYamlIndex(const QString val, YamlLookupType ylt) const
Expand Down Expand Up @@ -629,7 +629,7 @@ const QString BoardJson::getTrimYamlName(int index, YamlLookupType ylt) const

const bool BoardJson::isInputAvailable(int index) const
{
return isInputAvailable(m_inputs->at(index));
return (index >=0 && index < m_inputs->size()) ? isInputAvailable(m_inputs->at(index)) : false;
}

// static
Expand All @@ -641,7 +641,7 @@ bool BoardJson::isInputAvailable(const InputDefn & defn)

const bool BoardJson::isInputCalibrated(int index) const
{
return isInputCalibrated(m_inputs->at(index));
return (index >=0 && index < m_inputs->size()) ? isInputCalibrated(m_inputs->at(index)) : false;
}

// static
Expand All @@ -652,7 +652,7 @@ bool BoardJson::isInputCalibrated(const InputDefn & defn)

const bool BoardJson::isInputConfigurable(int index) const
{
return isInputConfigurable(m_inputs->at(index));
return (index >=0 && index < m_inputs->size()) ? isInputConfigurable(m_inputs->at(index)) : false;
}

// static
Expand All @@ -663,7 +663,7 @@ bool BoardJson::isInputConfigurable(const InputDefn & defn)

const bool BoardJson::isInputIgnored(int index) const
{
return isInputIgnored(m_inputs->at(index));
return (index >=0 && index < m_inputs->size()) ? isInputIgnored(m_inputs->at(index)) : true;
}

// static
Expand Down Expand Up @@ -698,7 +698,7 @@ bool BoardJson::isInputFlexJoystickAxis(const InputDefn & defn)

const bool BoardJson::isInputFlexPot(int index) const
{
return isInputFlexPot(m_inputs->at(index));
return (index >=0 && index < m_inputs->size()) ? isInputFlexPot(m_inputs->at(index)) : false;
}

// static
Expand Down Expand Up @@ -741,7 +741,7 @@ bool BoardJson::isInputRTCBat(const InputDefn & defn)

const bool BoardJson::isInputStick(int index) const
{
return isInputStick(m_inputs->at(index));
return (index >=0 && index < m_inputs->size()) ? isInputStick(m_inputs->at(index)) : false;
}

// static
Expand All @@ -752,7 +752,7 @@ bool BoardJson::isInputStick(const InputDefn & defn)

const bool BoardJson::isInputSwitch(int index) const
{
return isInputSwitch(m_inputs->at(index));
return (index >=0 && index < m_inputs->size()) ? isInputSwitch(m_inputs->at(index)) : false;
}

// static
Expand Down Expand Up @@ -792,7 +792,7 @@ bool BoardJson::isSwitchStd(const SwitchDefn & defn)

const bool BoardJson::isSwitchFlex(int index) const
{
return isSwitchFlex(m_switches->at(index));
return (index >=0 && index < m_switches->size()) ? isSwitchFlex(m_switches->at(index)) : false;
}

// static
Expand All @@ -806,7 +806,7 @@ bool BoardJson::isSwitchFlex(const SwitchDefn & defn)

const bool BoardJson::isSwitchFunc(int index) const
{
return isSwitchFunc(m_switches->at(index));
return (index >=0 && index < m_switches->size()) ? isSwitchFunc(m_switches->at(index)) : false;
}

// static
Expand Down
2 changes: 1 addition & 1 deletion companion/src/firmwares/customfunctiondata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ QString CustomFunctionData::funcToString(const AssignFunc func, const ModelData
return tr("RGB leds");
else if (func == FuncLCDtoVideo)
return tr("LCD to Video");
else if (func >= FuncPushCustomSwitch1 && func <= FuncPushCustomSwitchLast) {
else if (func >= FuncPushCustomSwitch1 && func <= FuncPushCustomSwitchLast && Boards::getCapability(getCurrentBoard(), Board::FunctionSwitches)) {
const int idx = Boards::getSwitchTypeOffset(Board::SWITCH_FUNC) + func - FuncPushCustomSwitch1 + 1;
return tr("Push Custom Switch %1").arg(RawSource(SOURCE_TYPE_SWITCH, idx).toString(model));
}
Expand Down

0 comments on commit 44e5d26

Please sign in to comment.