Fix raw switch index checks (#1403)

Resolves #1403
This commit is contained in:
Raphael Coeffic
2022-01-10 12:51:41 +01:00
parent 22762e0a16
commit 1c8639baea
@@ -102,7 +102,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str)
if (val_len >= 2 && val[0] == 'L' && (val[1] >= '0' && val[1] <= '9')) {
int sw_idx = std::stoi(sw_str_tmp.substr(1, val_len - 1));
if (sw_idx < CPN_MAX_LOGICAL_SWITCHES) {
if (sw_idx <= CPN_MAX_LOGICAL_SWITCHES) {
rhs = RawSwitch(SWITCH_TYPE_VIRTUAL, sw_idx);
}
@@ -123,7 +123,7 @@ RawSwitch YamlRawSwitchDecode(const std::string& sw_str)
// 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)) {
if ((sensor_idx > 0) && (sensor_idx <= CPN_MAX_SENSORS)) {
rhs = RawSwitch(SWITCH_TYPE_SENSOR, sensor_idx - 1);
}