[pipsolar] Guard handle_qmod_ against empty message (#16085)

This commit is contained in:
Jonathan Swoboda
2026-04-28 16:29:09 -04:00
committed by GitHub
parent c8dffcc9b8
commit 1f4136e76f
+7 -3
View File
@@ -433,13 +433,17 @@ void Pipsolar::handle_qpigs_(const char *message) {
}
void Pipsolar::handle_qmod_(const char *message) {
std::string mode;
char device_mode = char(message[1]);
if (this->last_qmod_) {
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_) {
mode = device_mode;
std::string mode;
mode = char(message[1]);
this->device_mode_->publish_state(mode);
}
}