vortigont / ESPAsyncButton

Event-based asynchronous button library for ESP32 family chips. It generate events for various button press patterns, like short/long press, clicks, autorepeat, multiple clicks
GNU Lesser General Public License v2.1
7 stars 1 forks source link

Initialize timers with nullptr #3

Closed rozsapeter96 closed 5 months ago

rozsapeter96 commented 6 months ago

Uninitialized pointer values for 'longPressTimer_h' and 'multiclickTimer_h' could cause crashes.

vortigont commented 5 months ago

Hello @rozsapeter96, have you faced any real crash due to this uninitialized pointer or it's just a safety measure? Actually those pointers are never used unless specific types of events are enabled per object instance, and when enabling event method is called, it will initialize timers and pointer variables.

rozsapeter96 commented 5 months ago

Hi @vortigont! Yes, my code crashed without setting those pointers to nullptr. I used buttons with click events and with debouncing enabled like this: for (auto button : buttons) { button->enableEvent(ESPButton::event_t::click); button->enableEvent(ESPButton::event_t::press, false); button->enableEvent(ESPButton::event_t::release, false); button->setDebounce(true); }

vortigont commented 5 months ago

I should check how timer structure initialization is done in the SDK. But agreed initializing pointers is a bulletproof safe. Thanks for your contribution and test case.

rozsapeter96 commented 5 months ago

Thank you @vortigont!