From a4c07b8472c52b2c068fe0d053b36c657773a858 Mon Sep 17 00:00:00 2001 From: proddy Date: Thu, 7 Nov 2024 12:17:08 +0100 Subject: [PATCH] fix liont warning --- src/mqtt.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mqtt.cpp b/src/mqtt.cpp index b6140f19c..a52e1d5ae 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -937,7 +937,8 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev // create the topic // depending on the type and whether the device entity is writable (i.e. a command) // https://developers.home-assistant.io/docs/core/entity - char topic[MQTT_TOPIC_MAX_SIZE] = {0}; + char topic[MQTT_TOPIC_MAX_SIZE]; + topic[0] = '\0'; // nullify, making it empty if (has_cmd) { // if it's a command then we can use Number, Switch, Select or Text. Otherwise stick to Sensor switch (type) { @@ -981,7 +982,7 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev } // if at this point we don't have a topic created yet, create a default sensor one. We always need a topic. - if (strlen(topic) == 0) { + if (!strnlen(topic, sizeof(topic))) { snprintf(topic, sizeof(topic), (type == DeviceValueType::BOOL) ? "binary_sensor/%s" : "sensor/%s", config_topic); // binary sensor (for booleans) }