khoih-prog / WiFiWebServer

This is simple yet complete WebServer library for AVR, Portenta_H7, Teensy, SAM DUE, SAMD, STM32, RP2040-based, etc. boards running WiFi modules/shields (WiFiNINA, CYW43439, U-Blox W101, W102, etc.). The functions are similar and compatible to ESP8266/ESP32 WebServer libraries to make life much easier to port sketches from ESP8266/ESP32. Now using WiFiMulti_Generic library
MIT License
104 stars 21 forks source link

Initialize pointer variables on object instantiation #6

Closed bizprof closed 3 years ago

bizprof commented 3 years ago

To avoid random crashes caused by using "delete[]" on objects that have been instantiated, but not yet initialized. Issues caused by uninitialized pointers are random, hard to replicate and mostly manifest themselves much further down the line. In a specific case, issues were created in Parsing-impl.h when a POST request contained Content-Type "multipart/form-data". By just initializing the pointers upon instantiation in WiFiWebServer.h, no changes are needed in Parsing-impl.h after all.

khoih-prog commented 3 years ago

That's good and make the code robust. Thanks.

khoih-prog commented 3 years ago

There is a typo at WiFiWebServer.h#L350, but I'll fix it.

 int               _currentArgCount;
 RequestArgument*  _currentArgs = nullptr;
 = nullptr