From a454f9c187008e791d05da8c378ac8f553f4ce3e Mon Sep 17 00:00:00 2001 From: gAlfonso-bit <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sun, 23 May 2021 10:10:55 -0400 Subject: [PATCH] UBFIX: sprite.c (#1442) Fix out-of-bounds array access in `SortSprites()`. Co-authored-by: Marcus Huderle --- gflib/sprite.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gflib/sprite.c b/gflib/sprite.c index c66b1e47dc..f97ecc712d 100644 --- a/gflib/sprite.c +++ b/gflib/sprite.c @@ -452,6 +452,10 @@ void SortSprites(void) // Although this doesn't result in a bug in the ROM, // the behavior is undefined. j--; +#ifdef UBFIX + if (j == 0) + break; +#endif sprite1 = &gSprites[sSpriteOrder[j - 1]]; sprite2 = &gSprites[sSpriteOrder[j]]; @@ -661,8 +665,7 @@ void ResetOamRange(u8 a, u8 b) for (i = a; i < b; i++) { - struct OamData *oamBuffer = gMain.oamBuffer; - oamBuffer[i] = *(struct OamData *)&gDummyOamData; + gMain.oamBuffer[i] = *(struct OamData *)&gDummyOamData; } }