mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 20:35:33 +03:00
Merge pull request #7443 from etracer65/cms_multiple_entry_wedging
Fix array overflow/wedge after multiple entries into CMS
This commit is contained in:
commit
46c4da05a1
1 changed files with 8 additions and 1 deletions
|
@ -81,6 +81,8 @@
|
||||||
#define CMS_MAX_DEVICE 4
|
#define CMS_MAX_DEVICE 4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define CMS_MENU_STACK_LIMIT 10
|
||||||
|
|
||||||
displayPort_t *pCurrentDisplay;
|
displayPort_t *pCurrentDisplay;
|
||||||
|
|
||||||
static displayPort_t *cmsDisplayPorts[CMS_MAX_DEVICE];
|
static displayPort_t *cmsDisplayPorts[CMS_MAX_DEVICE];
|
||||||
|
@ -175,7 +177,7 @@ typedef struct cmsCtx_s {
|
||||||
int8_t cursorRow; // cursorRow in the page
|
int8_t cursorRow; // cursorRow in the page
|
||||||
} cmsCtx_t;
|
} cmsCtx_t;
|
||||||
|
|
||||||
static cmsCtx_t menuStack[10];
|
static cmsCtx_t menuStack[CMS_MENU_STACK_LIMIT];
|
||||||
static uint8_t menuStackIdx = 0;
|
static uint8_t menuStackIdx = 0;
|
||||||
|
|
||||||
static int8_t pageCount; // Number of pages in the current menu
|
static int8_t pageCount; // Number of pages in the current menu
|
||||||
|
@ -633,6 +635,10 @@ long cmsMenuChange(displayPort_t *pDisplay, const void *ptr)
|
||||||
|
|
||||||
if (pMenu != currentCtx.menu) {
|
if (pMenu != currentCtx.menu) {
|
||||||
// Stack the current menu and move to a new menu.
|
// Stack the current menu and move to a new menu.
|
||||||
|
if (menuStackIdx >= CMS_MENU_STACK_LIMIT - 1) {
|
||||||
|
// menu stack limit reached - prevent array overflow
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
menuStack[menuStackIdx++] = currentCtx;
|
menuStack[menuStackIdx++] = currentCtx;
|
||||||
|
|
||||||
|
@ -691,6 +697,7 @@ void cmsMenuOpen(void)
|
||||||
return;
|
return;
|
||||||
cmsInMenu = true;
|
cmsInMenu = true;
|
||||||
currentCtx = (cmsCtx_t){ &menuMain, 0, 0 };
|
currentCtx = (cmsCtx_t){ &menuMain, 0, 0 };
|
||||||
|
menuStackIdx = 0;
|
||||||
setArmingDisabled(ARMING_DISABLED_CMS_MENU);
|
setArmingDisabled(ARMING_DISABLED_CMS_MENU);
|
||||||
} else {
|
} else {
|
||||||
// Switch display
|
// Switch display
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue