Fix out-of-bound loop UB (#218)

* avoid ub

* format

* torch
This commit is contained in:
petrie911
2024-04-20 16:47:46 -05:00
committed by GitHub
parent b3929bea72
commit e3716b5d48
14 changed files with 71 additions and 60 deletions
+4
View File
@@ -50,7 +50,11 @@ s32 D_ctx_80177B50[7];
s32 D_ctx_80177B70[7];
PlanetId D_ctx_80177B90[7];
s32 D_ctx_80177BB0[7];
#ifdef AVOID_UB
s32 D_ctx_80177BD8[24];
#else
s32 D_ctx_80177BD8[22]; // overruns gPrevPlanetTeamShields?
#endif
s32 gPrevPlanetTeamShields[6];
s32 D_ctx_80177C58[6];
u8 gSoundMode;
+4
View File
@@ -68,7 +68,11 @@ s32 Save_Read(void) {
(void) "EEPROM ROM[0] 正常\n";
return 0;
}
#ifdef AVOID_UB
for (i = 0; i < sizeof(SaveData); i++) {
#else
for (i = 0; i <= sizeof(SaveData); i++) { // should be <, but gets overwritten immediately.
#endif
gSaveFile.save.raw[i] = gSaveFile.backup.raw[i];
}
gSaveFile.save.checksum = gSaveFile.backup.checksum;