Fix debug menu memory overflow (#3154)

This commit is contained in:
Bassoonian 2023-07-19 23:38:09 +02:00 committed by GitHub
parent 6b5d1e7577
commit 6d7d7f109e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -211,6 +211,8 @@ enum { //Sound
#define DEBUG_NUMBER_ICON_X 210 #define DEBUG_NUMBER_ICON_X 210
#define DEBUG_NUMBER_ICON_Y 50 #define DEBUG_NUMBER_ICON_Y 50
#define DEBUG_MAX_MENU_ITEMS 50
// ******************************* // *******************************
struct DebugMonData struct DebugMonData
{ {
@ -234,7 +236,7 @@ struct DebugMonData
struct DebugMenuListData struct DebugMenuListData
{ {
struct ListMenuItem listItems[20 + 1]; struct ListMenuItem listItems[20 + 1];
u8 itemNames[PC_ITEMS_COUNT + 1][26]; u8 itemNames[DEBUG_MAX_MENU_ITEMS + 1][26];
u8 listId; u8 listId;
}; };
@ -1132,6 +1134,8 @@ static void Debug_RefreshListMenu(u8 taskId)
totalItems = 7; totalItems = 7;
} }
// Failsafe to prevent memory corruption
totalItems = min(totalItems, DEBUG_MAX_MENU_ITEMS);
// Copy item names for all entries but the last (which is Cancel) // Copy item names for all entries but the last (which is Cancel)
for(i = 0; i < totalItems; i++) for(i = 0; i < totalItems; i++)
{ {