From 0d619e780a9124347d7365e131a68ffdf2e2ea63 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Thu, 10 Nov 2022 18:32:28 +0100 Subject: [PATCH] Prevent null pointer exception It could occur that the command queue contained commands for inverters which are already deleted. Therefor it has to be checked that getInverterBySerial returns a valid inverter --- lib/Hoymiles/src/HoymilesRadio.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Hoymiles/src/HoymilesRadio.cpp b/lib/Hoymiles/src/HoymilesRadio.cpp index 8cbc6e1..db70d8b 100644 --- a/lib/Hoymiles/src/HoymilesRadio.cpp +++ b/lib/Hoymiles/src/HoymilesRadio.cpp @@ -127,7 +127,7 @@ void HoymilesRadio::loop() } } else { // If inverter was not found, assume the command is invalid - Serial.println(F("Invalid inverter found")); + Serial.println(F("RX: Invalid inverter found")); _commandQueue.pop(); _busyFlag = false; } @@ -137,8 +137,13 @@ void HoymilesRadio::loop() CommandAbstract* cmd = _commandQueue.front().get(); auto inv = Hoymiles.getInverterBySerial(cmd->getTargetAddress()); - inv->clearRxFragmentBuffer(); - sendEsbPacket(cmd); + if (nullptr != inv) { + inv->clearRxFragmentBuffer(); + sendEsbPacket(cmd); + } else { + Serial.println(F("TX: Invalid inverter found")); + _commandQueue.pop(); + } } } }