From 376cd0cf90ca49520dbba632454641d33bdfbb15 Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Sun, 19 Dec 2021 09:15:06 +0100 Subject: [PATCH] Fixed NULL access --- src/AmsConfiguration.cpp | 20 ++++++++++++-------- src/AmsConfiguration.h | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/AmsConfiguration.cpp b/src/AmsConfiguration.cpp index 2336eb78..716266f0 100644 --- a/src/AmsConfiguration.cpp +++ b/src/AmsConfiguration.cpp @@ -866,6 +866,8 @@ uint8_t AmsConfiguration::getTempSensorCount() { } TempSensorConfig* AmsConfiguration::getTempSensorConfig(uint8_t address[8]) { + if(tempSensors == NULL) + return NULL; for(int x = 0; x < tempSensorCount; x++) { TempSensorConfig *conf = tempSensors[x]; if(isSensorAddressEqual(conf->address, address)) { @@ -877,14 +879,16 @@ TempSensorConfig* AmsConfiguration::getTempSensorConfig(uint8_t address[8]) { void AmsConfiguration::updateTempSensorConfig(uint8_t address[8], const char name[32], bool common) { bool found = false; - for(int x = 0; x < tempSensorCount; x++) { - TempSensorConfig *data = tempSensors[x]; - if(isSensorAddressEqual(data->address, address)) { - found = true; - strcpy(data->name, name); - data->common = common; - } - } + if(tempSensors != NULL) { + for(int x = 0; x < tempSensorCount; x++) { + TempSensorConfig *data = tempSensors[x]; + if(isSensorAddressEqual(data->address, address)) { + found = true; + strcpy(data->name, name); + data->common = common; + } + } + } if(!found) { TempSensorConfig** tempSensors = new TempSensorConfig*[tempSensorCount+1]; if(this->tempSensors != NULL) { diff --git a/src/AmsConfiguration.h b/src/AmsConfiguration.h index 553fbb23..a02f89b7 100644 --- a/src/AmsConfiguration.h +++ b/src/AmsConfiguration.h @@ -319,7 +319,7 @@ private: bool wifiChanged, mqttChanged, meterChanged = true, domoChanged, ntpChanged = true, entsoeChanged = false; uint8_t tempSensorCount = 0; - TempSensorConfig** tempSensors; + TempSensorConfig** tempSensors = NULL; bool loadConfig83(int address); bool relocateConfig86();