mirror of
https://github.com/esphome/esphome.git
synced 2026-05-30 07:16:11 +08:00
[pipsolar] Guard handle_qmod_ against empty message (#16085)
This commit is contained in:
@@ -433,13 +433,17 @@ void Pipsolar::handle_qpigs_(const char *message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Pipsolar::handle_qmod_(const char *message) {
|
void Pipsolar::handle_qmod_(const char *message) {
|
||||||
std::string mode;
|
|
||||||
char device_mode = char(message[1]);
|
|
||||||
if (this->last_qmod_) {
|
if (this->last_qmod_) {
|
||||||
this->last_qmod_->publish_state(message);
|
this->last_qmod_->publish_state(message);
|
||||||
}
|
}
|
||||||
|
// QMOD response is "(M" where M is the device-mode character. Bail out if the
|
||||||
|
// message is shorter than 2 chars (e.g. empty error response from
|
||||||
|
// handle_poll_error_) — reading message[1] would otherwise be out of bounds.
|
||||||
|
if (message[0] == '\0' || message[1] == '\0')
|
||||||
|
return;
|
||||||
if (this->device_mode_) {
|
if (this->device_mode_) {
|
||||||
mode = device_mode;
|
std::string mode;
|
||||||
|
mode = char(message[1]);
|
||||||
this->device_mode_->publish_state(mode);
|
this->device_mode_->publish_state(mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user