Menu with no items
Steps to reproduce
- Make a typycal setup with ESP8266/ESP32
- Create GEMPage with no parentMenuPage and do not add any items
- Show the page
- You will get LoadProhibited exception in console and MCU reboots
Cause
GEMPage after constructing has null _menuItem. GEMPage::getMenuItem checks _menuItem->hidden, so null pointer dereference happens.
Fix
Add check for _menuItem != nullptr to the beginning of GEMPage::getMenuItem (and also GEMPage::getMenuItemNum)
Menu with all hidden items
Steps to reproduce
- Make a typycal setup with ESP8266/ESP32
- Create GEMPage with no parentMenuPage
- Add some items, but hide them all
- Show the page
- Press Cancel, Left or Right button
- You will get LoadProhibited exception in console and MCU reboots
Cause
GEM_u8g2::dispatchKeyPress calls _menuPageCurrent->getCurrentMenuItem()->type in lines 1204, 1213 and _menuPageCurrent->getMenuItem(0)->type in line 1218 (GEM_u8g2.cpp), but getMenuItem() and getCurrentMenuItem() would return nullptr when all elements are hidden.
Fix
Add check for nullptr in the lines above (i have not viewed GLCD and Adafruit version, but i suspect this problem as well as there)
N.B. It seems this problem can't be observed with Atmega MCU's because of no memory access control, but this code still has undefined behaviour, and its operating on Arduinos may rely on luck.
Menu with no items
Steps to reproduce
Cause
GEMPage after constructing has null
_menuItem.GEMPage::getMenuItemchecks_menuItem->hidden, so null pointer dereference happens.Fix
Add check for
_menuItem != nullptrto the beginning ofGEMPage::getMenuItem(and alsoGEMPage::getMenuItemNum)Menu with all hidden items
Steps to reproduce
Cause
GEM_u8g2::dispatchKeyPress calls
_menuPageCurrent->getCurrentMenuItem()->typein lines 1204, 1213 and_menuPageCurrent->getMenuItem(0)->typein line 1218 (GEM_u8g2.cpp), butgetMenuItem()andgetCurrentMenuItem()would return nullptr when all elements are hidden.Fix
Add check for nullptr in the lines above (i have not viewed GLCD and Adafruit version, but i suspect this problem as well as there)
N.B. It seems this problem can't be observed with Atmega MCU's because of no memory access control, but this code still has undefined behaviour, and its operating on Arduinos may rely on luck.