diff options
author | Kurausukun <lord.uber1@gmail.com> | 2021-06-26 04:04:22 -0400 |
---|---|---|
committer | Kurausukun <lord.uber1@gmail.com> | 2021-06-26 22:51:41 -0400 |
commit | 88bd618496b955da4505a8c106dd135235d02542 (patch) | |
tree | cd9083138e346cb42910409ee3a91490f37382e7 /src/fieldmap.c | |
parent | 8116790c0880cbe03e8d14efe88bf6000f283819 (diff) |
port UBFIXes from emerald
Diffstat (limited to 'src/fieldmap.c')
-rw-r--r-- | src/fieldmap.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/fieldmap.c b/src/fieldmap.c index 7ece8b622..400fc4cff 100644 --- a/src/fieldmap.c +++ b/src/fieldmap.c @@ -528,10 +528,14 @@ static bool32 SavedMapViewIsEmpty(void) u16 i; u32 marker = 0; +#ifndef UBFIX // BUG: This loop extends past the bounds of the mapView array. Its size is only 0x100. for (i = 0; i < 0x200; i++) marker |= gSaveBlock2Ptr->mapView[i]; - +#else + for (i = 0; i < NELEMS(gSaveBlock2Ptr->mapView); i++) + marker |= gSaveBlock2Ptr->mapView[i]; +#endif if (marker == 0) return TRUE; else @@ -746,14 +750,32 @@ struct MapConnection *sub_8059600(u8 direction, s32 x, s32 y) { s32 count; struct MapConnection *connection; + const struct MapConnections *connections = gMapHeader.connections; s32 i; - count = gMapHeader.connections->count; - connection = gMapHeader.connections->connections; + // UB: Multiple possible null dereferences +#ifdef UBFIX + if (connections != NULL) + { + count = connections->count; + connection = connections->connections; + if (connection != NULL) + { + for (i = 0; i < count; i++, connection++) + { + if (connection->direction == direction && sub_8059658(direction, x, y, connection) == TRUE) + return connection; + } + } + } +#else + count = connections->count; + connection = connections->connections; for (i = 0; i < count; i++, connection++) { if (connection->direction == direction && sub_8059658(direction, x, y, connection) == TRUE) return connection; } +#endif return NULL; } |