From e97a4f8776eee196595a826c0287549f81313e22 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 30 Apr 2023 04:23:23 +0200 Subject: [PATCH] Backport: Correct OOB check in PrepareInnerBorders() (#6064) Correct OOB check in PrepareInnerBorders() Co-authored-by: Stephen C. Wills --- Source/drlg_l4.cpp | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Source/drlg_l4.cpp b/Source/drlg_l4.cpp index e564dfa51..37d8c0836 100644 --- a/Source/drlg_l4.cpp +++ b/Source/drlg_l4.cpp @@ -1139,12 +1139,9 @@ static void uShape() } if (dung[i][j] == 1) { // BUGFIX: check that i + 1 < 20 and j + 1 < 20 (fixed) - if (i + 1 < 20 && j + 1 < 20 && - dung[i][j + 1] == 1 && dung[i + 1][j + 1] == 0) { - hallok[j] = TRUE; - } else { - hallok[j] = FALSE; - } + bool hasSouthWestRoom = j + 1 < 20 && dung[i][j + 1] == 1; + bool hasSouthRoom = i + 1 < 20 && j + 1 < 20 && dung[i + 1][j + 1] == 1; + hallok[j] = hasSouthWestRoom && !hasSouthRoom ? TRUE : FALSE; i = 0; } } @@ -1177,12 +1174,9 @@ static void uShape() } if (dung[i][j] == 1) { // BUGFIX: check that i + 1 < 20 and j + 1 < 20 (fixed) - if (i + 1 < 20 && j + 1 < 20 && - dung[i + 1][j] == 1 && dung[i + 1][j + 1] == 0) { - hallok[i] = TRUE; - } else { - hallok[i] = FALSE; - } + bool hasSouthEastRoom = i + 1 < 20 && dung[i + 1][j] == 1; + bool hasSouthRoom = i + 1 < 20 && j + 1 < 20 && dung[i + 1][j + 1] == 1; + hallok[i] = hasSouthEastRoom && !hasSouthRoom ? TRUE : FALSE; j = 0; } }