1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-06-07 09:01:49 +00:00

AVOID_UB: FileSelect_LoadGame out of bounds gBitFlags[-1] (#2527)

This commit is contained in:
Dragorn421 2025-05-12 13:25:22 +02:00 committed by GitHub
parent 39ae99c4cb
commit 0c6c112cb9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1955,7 +1955,16 @@ void FileSelect_LoadGame(GameState* thisx) {
swordEquipValue = swordEquipValue =
(gEquipMasks[EQUIP_TYPE_SWORD] & gSaveContext.save.info.equips.equipment) >> (EQUIP_TYPE_SWORD * 4); (gEquipMasks[EQUIP_TYPE_SWORD] & gSaveContext.save.info.equips.equipment) >> (EQUIP_TYPE_SWORD * 4);
gSaveContext.save.info.equips.equipment &= gEquipNegMasks[EQUIP_TYPE_SWORD]; 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); 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 #if PLATFORM_N64