[battle_controller_player.c] refactor and fix buffer overread (#3792)

Co-authored-by: sbird <sbird@no.tld>
This commit is contained in:
Philipp AUER 2023-12-22 23:24:12 +01:00 committed by GitHub
parent 38d67d9051
commit 5651bea82b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -225,16 +225,16 @@ static u16 GetPrevBall(u16 ballId)
return gBagPockets[BALLS_POCKET].itemSlots[i].itemId;
}
static u16 GetNextBall(u16 ballId)
static u32 GetNextBall(u32 ballId)
{
u16 ballNext = 0;
u32 ballNext = ITEM_NONE;
s32 i;
CompactItemsInBagPocket(&gBagPockets[BALLS_POCKET]);
for (i = 0; i < gBagPockets[BALLS_POCKET].capacity; i++)
for (i = 1; i < gBagPockets[BALLS_POCKET].capacity; i++)
{
if (ballId == gBagPockets[BALLS_POCKET].itemSlots[i].itemId)
if (ballId == gBagPockets[BALLS_POCKET].itemSlots[i-1].itemId)
{
ballNext = gBagPockets[BALLS_POCKET].itemSlots[i+1].itemId;
ballNext = gBagPockets[BALLS_POCKET].itemSlots[i].itemId;
break;
}
}