From 85b2319b593a69eb49a0e4c96aefb9a0cc812f02 Mon Sep 17 00:00:00 2001 From: Dontsov Evgeny Date: Mon, 24 Sep 2018 03:45:49 +0300 Subject: [PATCH 1/2] correct your idea about deflength --- WiFiManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 7eef612..9b083da 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -71,7 +71,7 @@ void WiFiManagerParameter::setValue(const char *defaultValue, int length) { int deflength = strlen(defaultValue); // length actual // use the defult length if it's longer, // @todo consider it might be useful to fail, so user knows they were wrong - if(_length < length){ + if(_length < deflength){ // Serial.println("defaultValue length mismatch"); _length = deflength; } From 7d42423894e3006978d8f7d1ab1b2107a446190b Mon Sep 17 00:00:00 2001 From: Dontsov Evgeny Date: Mon, 24 Sep 2018 04:19:21 +0300 Subject: [PATCH 2/2] value limit is length --- WiFiManager.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 9b083da..365eb4f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -68,20 +68,11 @@ void WiFiManagerParameter::setValue(const char *defaultValue, int length) { return; } _length = length; - int deflength = strlen(defaultValue); // length actual - // use the defult length if it's longer, - // @todo consider it might be useful to fail, so user knows they were wrong - if(_length < deflength){ - // Serial.println("defaultValue length mismatch"); - _length = deflength; - } - _value = new char[_length + 1]; - for (int i = 0; i < _length + 1; i++) { - _value[i] = 0; - } + _value = new char[_length + 1]; + memset(_value, 0, _length + 1); // explicit null + if (defaultValue != NULL) { strncpy(_value, defaultValue, _length); - _value[_length] = '\0'; // explicit null } } const char* WiFiManagerParameter::getValue() {