From ad648cc22d85f3ac9424a26df97f7bf40cd76b45 Mon Sep 17 00:00:00 2001 From: technyon Date: Tue, 7 Feb 2023 19:27:42 +0100 Subject: [PATCH] mqtt logging: allocate _path according to string length --- networkDevices/W5500Device.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/networkDevices/W5500Device.cpp b/networkDevices/W5500Device.cpp index ef0a531..0e0d8de 100644 --- a/networkDevices/W5500Device.cpp +++ b/networkDevices/W5500Device.cpp @@ -57,11 +57,10 @@ void W5500Device::initialize() if(_preferences->getBool(preference_mqtt_log_enabled)) { - _path = new char[200]; - memset(_path, 0, sizeof(_path)); - String pathStr = _preferences->getString(preference_mqtt_lock_path); pathStr.concat(mqtt_topic_log); + _path = new char[pathStr.length() + 1]; + memset(_path, 0, sizeof(_path)); strcpy(_path, pathStr.c_str()); Log = new MqttLogger(this, _path, MqttLoggerMode::MqttAndSerial); }