diff --git a/Source/drlg_l2.cpp b/Source/drlg_l2.cpp index be27f5536..778173f03 100644 --- a/Source/drlg_l2.cpp +++ b/Source/drlg_l2.cpp @@ -1,4 +1,7 @@ #ifndef SPAWN + +#include + #include "diablo.h" DEVILUTION_BEGIN_NAMESPACE @@ -349,8 +352,8 @@ static void DRLG_L2PlaceRndSet(BYTE *miniset, int rndper) } kk = sw * sh + 2; if (found == TRUE) { - for (yy = (sy - sh > 0 ? sy - sh : 0); yy < (sy + 2 * sh < DMAXY ? sy + 2 * sh : DMAXY) && found == TRUE; yy++) { - for (xx = (sx - sw > 0 ? sx - sw : 0); xx < (sx + 2 * sw < DMAXX ? sx + 2 * sw : DMAXX); xx++) { + for (yy = std::max(sy - sh, 0); yy < std::min(sy + 2 * sh, DMAXY) && found == TRUE; yy++) { + for (xx = std::max(sx - sw, 0); xx < std::min(sx + 2 * sw, DMAXX); xx++) { // BUGFIX: yy and xx can go out of bounds (fixed) if (dungeon[xx][yy] == miniset[kk]) { found = FALSE; diff --git a/Source/drlg_l3.cpp b/Source/drlg_l3.cpp index fcd7cc9c3..581676a67 100644 --- a/Source/drlg_l3.cpp +++ b/Source/drlg_l3.cpp @@ -1,4 +1,7 @@ #ifndef SPAWN + +#include + #include "diablo.h" DEVILUTION_BEGIN_NAMESPACE @@ -792,8 +795,8 @@ static void DRLG_L3Pool() found = TRUE; } poolchance = random_(0, 100); - for (j = (duny - totarea > 0 ? duny - totarea : 0); j < (duny + totarea < DMAXY ? duny + totarea : DMAXY); j++) { - for (i = (dunx - totarea > 0 ? dunx - totarea : 0); i < (dunx + totarea < DMAXY ? dunx + totarea : DMAXY); i++) { + for (j = std::max(duny - totarea, 0); j < std::min(duny + totarea, DMAXY); j++) { + for (i = std::max(dunx - totarea, 0); i < std::min(dunx + totarea, DMAXX); i++) { // BUGFIX: In the following swap the order to first do the // index checks and only then access dungeon[i][j] (fixed) if (dungeon[i][j] & 0x80) {