From 6aaa83a266348ac4accab79c77aeb903d2e3de96 Mon Sep 17 00:00:00 2001 From: Laurent Louf Date: Tue, 6 Feb 2018 14:12:13 +0100 Subject: [PATCH] Bug fix for problem discovered when setting length to 1 for additional parameters The initialization of the buffer holding the value stopped before the last character and storage did not take into account the extra-byte for end of string. --- WiFiManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index f97c4e5..7e9a9d9 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -34,7 +34,7 @@ void WiFiManagerParameter::init(const char *id, const char *placeholder, const c _placeholder = placeholder; _length = length; _value = new char[length + 1]; - for (int i = 0; i < length; i++) { + for (int i = 0; i < length + 1; i++) { _value[i] = 0; } if (defaultValue != NULL) { @@ -597,7 +597,7 @@ void WiFiManager::handleWifiSave() { //read parameter String value = server->arg(_params[i]->getID()).c_str(); //store it in array - value.toCharArray(_params[i]->_value, _params[i]->_length); + value.toCharArray(_params[i]->_value, _params[i]->_length + 1); DEBUG_WM(F("Parameter")); DEBUG_WM(_params[i]->getID()); DEBUG_WM(value);