Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix debug memory overflow #3154

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ enum { //Sound
#define DEBUG_NUMBER_ICON_X 210
#define DEBUG_NUMBER_ICON_Y 50

#define DEBUG_MAX_MENU_ITEMS 50

// *******************************
struct DebugMonData
{
Expand All @@ -234,7 +236,7 @@ struct DebugMonData
struct DebugMenuListData
{
struct ListMenuItem listItems[20 + 1];
u8 itemNames[PC_ITEMS_COUNT + 1][26];
u8 itemNames[DEBUG_MAX_MENU_ITEMS + 1][26];
u8 listId;
};

Expand Down Expand Up @@ -1132,6 +1134,8 @@ static void Debug_RefreshListMenu(u8 taskId)
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)
for(i = 0; i < totalItems; i++)
{
Expand Down