From f02dcbfdad2e72e4d4fe931a9313eed7802c0cff Mon Sep 17 00:00:00 2001 From: Misa Date: Wed, 9 Sep 2020 22:12:10 -0700 Subject: [PATCH] Don't manually write out INBOUNDS_ARR() checks When this is done, there is potential for a mistake to occur when writing out the bounds check, which is eliminated when using the macro instead. Luckily, this doesn't seem to have happened, but what's even worse is I hardcoded 400 instead of using SDL_arraysize(ed.level), so if the size of ed.level the bounds checks would all be wrong, which wouldn't be good. But that's fixed now, too. --- desktop_version/src/Entity.cpp | 2 +- desktop_version/src/Graphics.cpp | 2 +- desktop_version/src/Script.cpp | 4 ++-- desktop_version/src/editor.cpp | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/desktop_version/src/Entity.cpp b/desktop_version/src/Entity.cpp index dda3f2cc..b22e63be 100644 --- a/desktop_version/src/Entity.cpp +++ b/desktop_version/src/Entity.cpp @@ -1190,7 +1190,7 @@ void entityclass::createentity( float xp, float yp, int t, float vx /*= 0*/, flo #if !defined(NO_CUSTOM_LEVELS) // Special case for gray Warp Zone tileset! int room = game.roomx-100 + (game.roomy-100) * ed.maxwidth; - bool custom_gray = room >= 0 && room < 400 + bool custom_gray = INBOUNDS_ARR(room, ed.level) && ed.level[room].tileset == 3 && ed.level[room].tilecol == 6; #else bool custom_gray = false; diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index e54a8af2..e1c1f41c 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -1569,7 +1569,7 @@ void Graphics::drawentities() #if !defined(NO_CUSTOM_LEVELS) // Special case for gray Warp Zone tileset! int room = game.roomx-100 + (game.roomy-100) * ed.maxwidth; - bool custom_gray = room >= 0 && room < 400 + bool custom_gray = INBOUNDS_ARR(room, ed.level) && ed.level[room].tileset == 3 && ed.level[room].tilecol == 6; #else bool custom_gray = false; diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 520d8322..82a6c77e 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -111,7 +111,7 @@ void scriptclass::run() int temprx=ss_toi(words[1])-1; int tempry=ss_toi(words[2])-1; int curlevel=temprx+(ed.maxwidth*(tempry)); - bool inbounds = curlevel >= 0 && curlevel < 400; + bool inbounds = INBOUNDS_ARR(curlevel, ed.level); if (inbounds) { ed.level[curlevel].warpdir=ss_toi(words[3]); @@ -151,7 +151,7 @@ void scriptclass::run() if (words[0] == "ifwarp") { int room = ss_toi(words[1])-1+(ed.maxwidth*(ss_toi(words[2])-1)); - if (room >= 0 && room < 400 && ed.level[room].warpdir == ss_toi(words[3])) + if (INBOUNDS_ARR(room, ed.level) && ed.level[room].warpdir == ss_toi(words[3])) { load("custom_"+words[4]); position--; diff --git a/desktop_version/src/editor.cpp b/desktop_version/src/editor.cpp index 8f7d19da..98b38298 100644 --- a/desktop_version/src/editor.cpp +++ b/desktop_version/src/editor.cpp @@ -1567,7 +1567,7 @@ void editorclass::switch_tileset(const bool reversed /*= false*/) { const char* tilesets[] = {"Space Station", "Outside", "Lab", "Warp Zone", "Ship"}; const size_t roomnum = levx + levy*maxwidth; - if (roomnum >= SDL_arraysize(level)) + if (!INBOUNDS_ARR(roomnum, level)) { return; } @@ -1601,7 +1601,7 @@ void editorclass::switch_tileset(const bool reversed /*= false*/) void editorclass::switch_tilecol(const bool reversed /*= false*/) { const size_t roomnum = levx + levy*maxwidth; - if (roomnum >= SDL_arraysize(level)) + if (!INBOUNDS_ARR(roomnum, level)) { return; } @@ -1626,7 +1626,7 @@ void editorclass::switch_tilecol(const bool reversed /*= false*/) void editorclass::clamp_tilecol(const int rx, const int ry, const bool wrap /*= false*/) { const size_t roomnum = rx + ry*maxwidth; - if (roomnum >= SDL_arraysize(level)) + if (!INBOUNDS_ARR(roomnum, level)) { return; } @@ -1676,7 +1676,7 @@ void editorclass::clamp_tilecol(const int rx, const int ry, const bool wrap /*= void editorclass::switch_enemy(const bool reversed /*= false*/) { const size_t roomnum = levx + levy*maxwidth; - if (roomnum >= SDL_arraysize(level)) + if (!INBOUNDS_ARR(roomnum, level)) { return; }