use precise length for storing state topic

This commit is contained in:
Nicu Hodos 2025-10-10 23:34:42 +02:00
parent 130f4eb6a2
commit 12663901ab

View File

@ -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) {