From 1f500fddd1348daffcc27b61f1e53a2f3fbc611d Mon Sep 17 00:00:00 2001 From: Alex Goris Date: Sun, 8 Jan 2017 23:31:53 +0100 Subject: [PATCH] Don't add custom parameters if array size is exceeded array containing custom parameters is initialised at class initialization time with a fixed value. When we later try to add more parameters than the array allows we will now discard the offending parameters and make a debug logging so the developer knows what's going on. Might be further improved as per this answer on StackOverflow: http://stackoverflow.com/a/12271501 This would allow the array size to be specified at initialisation time, and would give flexibility to the developer to decide how big the array should be. closes tzapu/WiFiManager#285 --- WiFiManager.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 93bf578..06e7481 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -64,6 +64,14 @@ WiFiManager::WiFiManager() { } void WiFiManager::addParameter(WiFiManagerParameter *p) { + if(_paramsCount + 1 > WIFI_MANAGER_MAX_PARAMS) + { + //Max parameters exceeded! + DEBUG_WM("WIFI_MANAGER_MAX_PARAMS exceeded, increase number (in WiFiManager.h) before adding more parameters!"); + DEBUG_WM("Skipping parameter with ID:"); + DEBUG_WM(p->getID()); + return; + } _params[_paramsCount] = p; _paramsCount++; DEBUG_WM("Adding parameter");