From d0a1ce05f2d65527f2a35507eef6bf667042688b Mon Sep 17 00:00:00 2001 From: SteWers Date: Tue, 4 Jul 2023 18:22:41 +0200 Subject: [PATCH] [DS18x20] change to calloc() --- tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino | 9 +++++++-- tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino b/tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino index ec329217f60c..cc0586649b86 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino @@ -50,6 +50,8 @@ #define DS18X20_MAX_SENSORS 8 #endif +#define DS18X20_ALIAS_LEN 17 + const char kDs18x20Types[] PROGMEM = "DS18x20|DS18S20|DS1822|DS18B20|MAX31850"; uint8_t ds18x20_chipids[] = { 0, DS18S20_CHIPID, DS1822_CHIPID, DS18B20_CHIPID, MAX31850_CHIPID }; @@ -63,7 +65,7 @@ struct { uint8_t valid; int8_t pins_id; #ifdef DS18x20_USE_ID_ALIAS - char alias[17] = "0"; + char *alias = (char*)calloc(DS18X20_ALIAS_LEN, 1); #endif // DS18x20_USE_ID_ALIAS } ds18x20_sensor[DS18X20_MAX_SENSORS]; @@ -357,6 +359,9 @@ void Ds18x20Init(void) { for (uint32_t j = 6; j > 0; j--) { ids[DS18X20Data.sensors] = ids[DS18X20Data.sensors] << 8 | ds18x20_sensor[DS18X20Data.sensors].address[j]; } +#ifdef DS18x20_USE_ID_ALIAS + ds18x20_sensor[DS18X20Data.sensors].alias[0] = '0'; +#endif ds18x20_sensor[DS18X20Data.sensors].pins_id = pins; DS18X20Data.sensors++; } @@ -590,7 +595,7 @@ void CmndDSAlias(void) { sprintf(address+2*j, "%02X", ds18x20_sensor[i].address[7-j]); } if (!strncmp(Argument1, address, 12) && Argument2[0]) { - snprintf_P(ds18x20_sensor[i].alias, sizeof(ds18x20_sensor[i].alias), PSTR("%s"), Argument2); + snprintf_P(ds18x20_sensor[i].alias, DS18X20_ALIAS_LEN, PSTR("%s"), Argument2); break; } } diff --git a/tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino b/tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino index 557b741fa301..914d9532af3f 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino @@ -47,6 +47,8 @@ #define DS18X20_MAX_SENSORS 8 #endif +#define DS18X20_ALIAS_LEN 17 + const char kDs18x20Types[] PROGMEM = "DS18x20|DS18S20|DS1822|DS18B20|MAX31850"; uint8_t ds18x20_chipids[] = { 0, DS18S20_CHIPID, DS1822_CHIPID, DS18B20_CHIPID, MAX31850_CHIPID }; @@ -62,7 +64,7 @@ struct { uint8_t valid; int8_t pins_id; #ifdef DS18x20_USE_ID_ALIAS - char alias[17] = "0"; + char *alias = (char*)calloc(DS18X20_ALIAS_LEN, 1); #endif //DS18x20_USE_ID_ALIAS } ds18x20_sensor[DS18X20_MAX_SENSORS]; @@ -108,6 +110,9 @@ void Ds18x20Search(void) { (ds18x20_sensor[num_sensors].address[0] == DS1822_CHIPID) || (ds18x20_sensor[num_sensors].address[0] == DS18B20_CHIPID) || (ds18x20_sensor[num_sensors].address[0] == MAX31850_CHIPID))) { +#ifdef DS18x20_USE_ID_ALIAS + ds18x20_sensor[DS18X20Data.sensors].alias[0] = '0'; +#endif ds18x20_sensor[num_sensors].pins_id = pins; num_sensors++; } @@ -333,7 +338,7 @@ void CmndDSAlias(void) { sprintf(address+2*j, "%02X", ds18x20_sensor[i].address[7-j]); } if (!strncmp(Argument1, address, 12) && Argument2[0]) { - snprintf_P(ds18x20_sensor[i].alias, sizeof(ds18x20_sensor[i].alias), PSTR("%s"), Argument2); + snprintf_P(ds18x20_sensor[i].alias, DS18X20_ALIAS_LEN, PSTR("%s"), Argument2); break; } }