diff options
| author | Dragorn421 <Dragorn421@users.noreply.github.com> | 2025-05-12 13:25:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-12 07:25:22 -0400 |
| commit | 0c6c112cb9a3a8f12d0f4865743853857bbdc88e (patch) | |
| tree | 9d657809a8842a79f03a84ad201a7068c2e56f55 /src | |
| parent | 39ae99c4cba4a69a4f977607a2446d946097c3d0 (diff) | |
AVOID_UB: FileSelect_LoadGame out of bounds `gBitFlags[-1]` (#2527)
Diffstat (limited to 'src')
| -rw-r--r-- | src/overlays/gamestates/ovl_file_choose/z_file_choose.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index c3d9302ee..e8934c373 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -1955,7 +1955,16 @@ void FileSelect_LoadGame(GameState* thisx) { swordEquipValue = (gEquipMasks[EQUIP_TYPE_SWORD] & gSaveContext.save.info.equips.equipment) >> (EQUIP_TYPE_SWORD * 4); gSaveContext.save.info.equips.equipment &= gEquipNegMasks[EQUIP_TYPE_SWORD]; +#ifndef AVOID_UB + //! @bug swordEquipValue can be 0 (EQUIP_VALUE_SWORD_NONE) here (typically, when first starting the game). + //! This leads to reading gBitFlags[-1] (out of bounds). + // gBitFlags[-1] turns out to be 0 in matching versions so this is inconsequential. gSaveContext.save.info.inventory.equipment ^= OWNED_EQUIP_FLAG(EQUIP_TYPE_SWORD, swordEquipValue - 1); +#else + if (swordEquipValue != EQUIP_VALUE_SWORD_NONE) { + gSaveContext.save.info.inventory.equipment ^= OWNED_EQUIP_FLAG(EQUIP_TYPE_SWORD, swordEquipValue - 1); + } +#endif } #if PLATFORM_N64 |
