diff options
author | GriffinR <griffin.g.richards@gmail.com> | 2020-12-26 22:08:48 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-26 22:08:48 -0500 |
commit | e1fd2f2a89e4a84c6a69a90ac54263999d3c275b (patch) | |
tree | dd423c22391406701c3d3074dff0b69818269f51 /src/fieldmap.c | |
parent | d74f739e05c4ed9646a9e42b4400243474dd9fa8 (diff) | |
parent | 127bb97c0e5c50b9f22715bdf4e958937f7ef992 (diff) |
Merge pull request #1280 from Sierraffinity/master
Add fixes for undefined behavior with modern compiler
Diffstat (limited to 'src/fieldmap.c')
-rw-r--r-- | src/fieldmap.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/fieldmap.c b/src/fieldmap.c index 49337ebbe..296c4edf2 100644 --- a/src/fieldmap.c +++ b/src/fieldmap.c @@ -797,15 +797,33 @@ bool8 CameraMove(int x, int y) struct MapConnection *sub_8088950(u8 direction, int x, int y) { int count; - struct MapConnection *connection; int i; - count = gMapHeader.connections->count; - connection = gMapHeader.connections->connections; + struct MapConnection *connection; + const struct MapConnections *connections = gMapHeader.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_80889A8(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_80889A8(direction, x, y, connection) == TRUE) return connection; } +#endif return NULL; } |