From 423c79b572f65b8b5ce5a0046ed3332c1f9814d0 Mon Sep 17 00:00:00 2001 From: Misa Date: Wed, 24 Mar 2021 12:14:28 -0700 Subject: [PATCH] Add bounds checks to room explored getter and setter This means you can no longer cause Undefined Behavior by exploring a room that is outside the array of explored room statuses. --- desktop_version/src/Map.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/desktop_version/src/Map.cpp b/desktop_version/src/Map.cpp index e46553a7..68469963 100644 --- a/desktop_version/src/Map.cpp +++ b/desktop_version/src/Map.cpp @@ -724,13 +724,20 @@ int mapclass::area(int _rx, int _ry) bool mapclass::isexplored(const int rx, const int ry) { const int roomnum = rx + ry*20; - return explored[roomnum]; + if (INBOUNDS_ARR(roomnum, explored)) + { + return explored[roomnum]; + } + return false; } void mapclass::setexplored(const int rx, const int ry, const bool status) { const int roomnum = rx + ry*20; - explored[roomnum] = status; + if (INBOUNDS_ARR(roomnum, explored)) + { + explored[roomnum] = status; + } } void mapclass::exploretower(void)