1
0
Fork 0
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:
Michael Keller 2019-01-22 18:10:37 +13:00 committed by GitHub
commit 46c4da05a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -81,6 +81,8 @@
#define CMS_MAX_DEVICE 4
#endif
#define CMS_MENU_STACK_LIMIT 10
displayPort_t *pCurrentDisplay;
static displayPort_t *cmsDisplayPorts[CMS_MAX_DEVICE];
@ -175,7 +177,7 @@ typedef struct cmsCtx_s {
int8_t cursorRow; // cursorRow in the page
} cmsCtx_t;
static cmsCtx_t menuStack[10];
static cmsCtx_t menuStack[CMS_MENU_STACK_LIMIT];
static uint8_t menuStackIdx = 0;
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) {
// 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;
@ -691,6 +697,7 @@ void cmsMenuOpen(void)
return;
cmsInMenu = true;
currentCtx = (cmsCtx_t){ &menuMain, 0, 0 };
menuStackIdx = 0;
setArmingDisabled(ARMING_DISABLED_CMS_MENU);
} else {
// Switch display