fix possible lost pointers, could cause a crash

This commit is contained in:
proddy
2026-09-24 22:12:19 +02:00
parent 491bb01088
commit 8b1de52f55
2 changed files with 9 additions and 14 deletions
+5 -4
View File
@@ -144,8 +144,8 @@ void AnalogSensor::reload(bool get_nvs) {
// load the list of analog sensors from the customization service
// and store them locally and then activate them
EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
auto it = sensors_.begin();
for (auto & sensor_ : sensors_) {
for (auto it = sensors_.begin(); it != sensors_.end();) {
auto & sensor_ = *it;
// update existing sensors
bool found = false;
for (const auto & sensor : settings.analogCustomizations) { // search customlist
@@ -170,9 +170,10 @@ void AnalogSensor::reload(bool get_nvs) {
}
}
if (!found) {
sensors_.erase(it);
it = sensors_.erase(it);
} else {
++it;
}
it++;
}
// add new sensors from list
+4 -10
View File
@@ -542,16 +542,10 @@ Command::CmdFunction * Command::find_command(const uint8_t device_type, const ui
}
void Command::erase_device_commands(const uint8_t device_type) {
if (cmdfunctions_.empty()) {
return;
}
auto it = cmdfunctions_.end();
do {
int i = it - cmdfunctions_.begin();
if (cmdfunctions_[i].device_type_ == device_type) {
cmdfunctions_.erase(it);
}
} while (it-- > cmdfunctions_.begin());
cmdfunctions_.erase(std::remove_if(cmdfunctions_.begin(),
cmdfunctions_.end(),
[device_type](const CmdFunction & cf) { return cf.device_type_ == device_type; }),
cmdfunctions_.end());
}
void Command::erase_command(const uint8_t device_type, const char * cmd, uint8_t flag) {