From 12663901ab40a584c71715d847111612b23e1991 Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Fri, 10 Oct 2025 23:34:42 +0200 Subject: [PATCH] use precise length for storing state topic --- src/ha.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ha.h b/src/ha.h index d89a6be..4f43010 100644 --- a/src/ha.h +++ b/src/ha.h @@ -186,14 +186,17 @@ namespace Ha { }; struct State : Config { - char topic[TOPIC_SIZE] = {}; + char* topic; const char* jsonAttributesTemplate = nullptr; const char* valueTemplate = nullptr; - State(Component* cmp) : cmp(cmp) {} + State(Component* cmp) : cmp(cmp) { + auto len = snprintf(nullptr, 0, BASE_TOPIC"/state", cmp->id); + topic = new char[len + 1]; + } void withStateTopic() { - snprintf(topic, sizeof(topic), BASE_TOPIC"/state", cmp->id); + sprintf(topic, BASE_TOPIC"/state", cmp->id); } void updateState(const char* message) {