From d8c1b55b2223ee0b040ce4abfc1ae60b34f637ab Mon Sep 17 00:00:00 2001 From: cawtds <38510667+cawtds@users.noreply.github.com> Date: Sat, 26 Apr 2025 00:21:03 +0200 Subject: [PATCH] ub fix for OOB access with gActiveBattler --- src/battle_controllers.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/battle_controllers.c b/src/battle_controllers.c index 02276a7e14..cf50d4c340 100644 --- a/src/battle_controllers.c +++ b/src/battle_controllers.c @@ -57,6 +57,11 @@ void SetUpBattleVarsAndBirchZigzagoon(void) gBattleControllerExecFlags = 0; ClearBattleAnimationVars(); ClearBattleMonForms(); +// UB: at the start of a battle CheckMoveLimitations is called with gActiveBattler +// from the previous battle, which can lead to multiple arrays being accessed out of bounds +#ifdef UBFIX + gActiveBattler = 0; +#endif BattleAI_HandleItemUseBeforeAISetup(0xF); if (gBattleTypeFlags & BATTLE_TYPE_FIRST_BATTLE)