mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-15 15:41:21 +10:00
Merge pull request #374 from liebman/allocate-params-array
use malloc/free for WiFiManagerParameter* array instead of hard coding.
This commit is contained in:
+27
-7
@@ -66,22 +66,42 @@ const char* WiFiManagerParameter::getCustomHTML() {
|
||||
return _customHTML;
|
||||
}
|
||||
|
||||
|
||||
WiFiManager::WiFiManager() {
|
||||
_max_params = WIFI_MANAGER_MAX_PARAMS;
|
||||
_params = (WiFiManagerParameter**)malloc(_max_params * sizeof(WiFiManagerParameter*));
|
||||
}
|
||||
|
||||
void WiFiManager::addParameter(WiFiManagerParameter *p) {
|
||||
if(_paramsCount + 1 > WIFI_MANAGER_MAX_PARAMS)
|
||||
WiFiManager::~WiFiManager()
|
||||
{
|
||||
if (_params != NULL)
|
||||
{
|
||||
DEBUG_WM(F("freeing allocated params!"));
|
||||
free(_params);
|
||||
}
|
||||
}
|
||||
|
||||
bool WiFiManager::addParameter(WiFiManagerParameter *p) {
|
||||
if(_paramsCount + 1 > _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;
|
||||
// rezise the params array
|
||||
_max_params += WIFI_MANAGER_MAX_PARAMS;
|
||||
DEBUG_WM(F("Increasing _max_params to:"));
|
||||
DEBUG_WM(_max_params);
|
||||
WiFiManagerParameter** new_params = (WiFiManagerParameter**)realloc(_params, _max_params * sizeof(WiFiManagerParameter*));
|
||||
if (new_params != NULL) {
|
||||
_params = new_params;
|
||||
} else {
|
||||
DEBUG_WM("ERROR: failed to realloc params, size not increased!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
_params[_paramsCount] = p;
|
||||
_paramsCount++;
|
||||
DEBUG_WM("Adding parameter");
|
||||
DEBUG_WM(p->getID());
|
||||
return true;
|
||||
}
|
||||
|
||||
void WiFiManager::setupConfigPortal() {
|
||||
|
||||
Reference in New Issue
Block a user