diff --git a/companion/src/firmwares/edgetx/yaml_modeldata.cpp b/companion/src/firmwares/edgetx/yaml_modeldata.cpp index 4cc939147..45e5f8a4b 100644 --- a/companion/src/firmwares/edgetx/yaml_modeldata.cpp +++ b/companion/src/firmwares/edgetx/yaml_modeldata.cpp @@ -306,7 +306,11 @@ static int32_t YamlReadLimitValue(const YAML::Node& node, int32_t shift = 0) return 10000 + std::stoi(val.substr(2)); } - return std::stoi(val) + shift; + try { + return std::stoi(val) + shift; + } catch(...) { + throw YAML::TypedBadConversion(node.Mark()); + } } static std::string YamlWriteLimitValue(int32_t sval, int32_t shift = 0) @@ -593,7 +597,9 @@ struct convert { if (str == "none") { rhs.src = 0; } else { - rhs.src = std::stoi(str) + 1; + try { + rhs.src = std::stoi(str) + 1; + } catch(...) {} } } return true; diff --git a/companion/src/firmwares/edgetx/yaml_moduledata.cpp b/companion/src/firmwares/edgetx/yaml_moduledata.cpp index 2089ee683..a6c84d8d5 100644 --- a/companion/src/firmwares/edgetx/yaml_moduledata.cpp +++ b/companion/src/firmwares/edgetx/yaml_moduledata.cpp @@ -333,14 +333,16 @@ bool convert::decode(const Node& node, ModuleData& rhs) subType >> st_str; if (!st_str.empty()) { size_t pos = 0; - int rfProtocol = std::stoi(st_str, &pos); - st_str = st_str.substr(pos + 1); - int rfSubType = std::stoi(st_str); - convertMultiProtocolToEtx(&rfProtocol, &rfSubType); - if (rfProtocol > 0) { - rhs.multi.rfProtocol = rfProtocol - 1; - rhs.subType = rfSubType; - } + try { + int rfProtocol = std::stoi(st_str, &pos); + st_str = st_str.substr(pos + 1); + int rfSubType = std::stoi(st_str); + convertMultiProtocolToEtx(&rfProtocol, &rfSubType); + if (rfProtocol > 0) { + rhs.multi.rfProtocol = rfProtocol - 1; + rhs.subType = rfSubType; + } + } catch(...) {} } } break; } diff --git a/companion/src/firmwares/edgetx/yaml_rawsource.cpp b/companion/src/firmwares/edgetx/yaml_rawsource.cpp index d700c712b..4d8e98cfd 100644 --- a/companion/src/firmwares/edgetx/yaml_rawsource.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawsource.cpp @@ -102,12 +102,13 @@ RawSource YamlRawSourceDecode(const std::string& src_str) const char* val = src_str.data(); size_t val_len = src_str.size(); - if (val_len > 0 && val[0] == 'I') { + if (val_len > 1 && val[0] == 'I' + && (val[1] >= '0') && (val[1] <= '9')) { int idx = std::stoi(src_str.substr(1)); - if (idx < CPN_MAX_INPUTS) + if (idx < CPN_MAX_INPUTS) { rhs = RawSource(SOURCE_TYPE_VIRTUAL_INPUT, idx); - + } } else if (val_len >= 2 && val[0] == 'S' && val[1] >= 'A' diff --git a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp index bea8f11c4..34ae49321 100644 --- a/companion/src/firmwares/edgetx/yaml_rawswitch.cpp +++ b/companion/src/firmwares/edgetx/yaml_rawswitch.cpp @@ -101,9 +101,9 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) if (val_len >= 2 && val[0] == 'L' && (val[1] >= '0' && val[1] <= '9')) { - if (std::stoi(sw_str_tmp.substr(1, val_len - 1)) < CPN_MAX_LOGICAL_SWITCHES) { - rhs = RawSwitch(SWITCH_TYPE_VIRTUAL, - std::stoi(sw_str_tmp.substr(1, val_len - 1))); + int sw_idx = std::stoi(sw_str_tmp.substr(1, val_len - 1)); + if (sw_idx < CPN_MAX_LOGICAL_SWITCHES) { + rhs = RawSwitch(SWITCH_TYPE_VIRTUAL, sw_idx); } } else if (val_len > 3 && val[0] == '6' && val[1] == 'P' && @@ -121,9 +121,10 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str) } else if (val_len >= 2 && val[0] == 'T' && (val[1] >= '0' && val[1] <= '9')) { - if (std::stoi(sw_str_tmp.substr(1, val_len - 1)) < CPN_MAX_SENSORS) { - rhs = RawSwitch(SWITCH_TYPE_SENSOR, - std::stoi(sw_str_tmp.substr(1, val_len - 1)) - 1); + // starts at T1 + int sensor_idx = std::stoi(sw_str_tmp.substr(1, val_len - 1)); + if ((sensor_idx > 0) && (sensor_idx < CPN_MAX_SENSORS)) { + rhs = RawSwitch(SWITCH_TYPE_SENSOR, sensor_idx - 1); } } else if (sw_str_tmp.substr(0, 4) == std::string("Trim")) { diff --git a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp index 75b0e05af..7ab997c55 100644 --- a/companion/src/firmwares/edgetx/yaml_switchconfig.cpp +++ b/companion/src/firmwares/edgetx/yaml_switchconfig.cpp @@ -50,10 +50,12 @@ const YamlLookupTable sliderConfigLut = { int YamlStickLookup::name2idx(const std::string& name) { - int idx = std::stoi(name); - if (idx < 4) { - return idx; - } + try { + int idx = std::stoi(name); + if (idx < 4) { + return idx; + } + } catch(...) {} return -1; }