mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-10-28 11:14:58 +00:00
fix possible lost pointers, could cause a crash
This commit is contained in:
@@ -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
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user