Skip to content

Commit

Permalink
Checks for out of bounds;
Browse files Browse the repository at this point in the history
  • Loading branch information
de4me committed Nov 21, 2019
1 parent 7d21901 commit e4a9d68
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions Source/drlg_l3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ static void DRLG_L3River()
rx = 0;
ry = 0;
i = 0;
while (ry<DMAXY && i<100 && (dungeon[rx][ry] < 25 || dungeon[rx][ry] > 28)) {
while (ry<DMAXY && i<100 && (dungeon[rx][ry] < 25 || dungeon[rx][ry] > 28)) {
rx = random_(0, DMAXX);
ry = random_(0, DMAXY);
i++;
Expand All @@ -441,10 +441,10 @@ static void DRLG_L3River()
}
}
}
// BUGFIX: Continue if `ry >= DMAXY` (fixed)
if (ry >= DMAXY)
// BUGFIX: Continue if `ry >= DMAXY` (fixed)
if (ry >= DMAXY)
continue;
if (i >= 100) {
if (i >= 100) {
return;
}
switch (dungeon[rx][ry]) {
Expand Down Expand Up @@ -556,9 +556,9 @@ static void DRLG_L3River()
ry = py;
}
}
if(rx<2 || rx+2>=DMAXX) continue;
if(ry<2 || ry+2>=DMAXY) continue;
if (dir == 0 && dungeon[rx][ry - 1] == 10 && dungeon[rx][ry - 2] == 8) {
if(rx<2 || rx+2>=DMAXX) continue;
if(ry<2 || ry+2>=DMAXY) continue;
if (dir == 0 && dungeon[rx][ry - 1] == 10 && dungeon[rx][ry - 2] == 8) {
river[0][riveramt] = rx;
river[1][riveramt] = ry - 1;
river[2][riveramt] = 24;
Expand All @@ -570,7 +570,7 @@ static void DRLG_L3River()
}
bail = TRUE;
}
if (dir == 1 && dungeon[rx][ry + 1] == 2 && dungeon[rx][ry + 2] == 8) {
if (dir == 1 && dungeon[rx][ry + 1] == 2 && dungeon[rx][ry + 2] == 8) {
river[0][riveramt] = rx;
river[1][riveramt] = ry + 1;
river[2][riveramt] = 42;
Expand All @@ -582,7 +582,7 @@ static void DRLG_L3River()
}
bail = TRUE;
}
if (dir == 2 && dungeon[rx + 1][ry] == 4 && dungeon[rx + 2][ry] == 8) {
if (dir == 2 && dungeon[rx + 1][ry] == 4 && dungeon[rx + 2][ry] == 8) {
river[0][riveramt] = rx + 1;
river[1][riveramt] = ry;
river[2][riveramt] = 43;
Expand All @@ -594,7 +594,7 @@ static void DRLG_L3River()
}
bail = TRUE;
}
if (dir == 3 && dungeon[rx - 1][ry] == 9 && dungeon[rx - 2][ry] == 8) {
if (dir == 3 && dungeon[rx - 1][ry] == 9 && dungeon[rx - 2][ry] == 8) {
river[0][riveramt] = rx - 1;
river[1][riveramt] = ry;
river[2][riveramt] = 23;
Expand Down Expand Up @@ -1083,13 +1083,15 @@ void AddFenceDoors()
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 7) {
if (i > 0 && i < DMAXX - 1)
if (dungeon[i - 1][j] <= 152 && dungeon[i - 1][j] >= 130
&& dungeon[i + 1][j] <= 152 && dungeon[i + 1][j] >= 130) {
dungeon[i][j] = 146;
continue;
}
}
if (dungeon[i][j] == 7) {
if (j > 0 && j < DMAXY - 1)
if (dungeon[i][j - 1] <= 152 && dungeon[i][j - 1] >= 130
&& dungeon[i][j + 1] <= 152 && dungeon[i][j + 1] >= 130) {
dungeon[i][j] = 147;
Expand All @@ -1107,13 +1109,15 @@ void FenceDoorFix()
for (j = 0; j < DMAXY; j++) {
for (i = 0; i < DMAXX; i++) {
if (dungeon[i][j] == 146) {
if (i > 0 && i < DMAXX - 1)
if (dungeon[i + 1][j] > 152 || dungeon[i + 1][j] < 130
|| dungeon[i - 1][j] > 152 || dungeon[i - 1][j] < 130) {
dungeon[i][j] = 7;
continue;
}
}
if (dungeon[i][j] == 146) {
if (i > 0 && i < DMAXX - 1)
if (dungeon[i + 1][j] != 130 && dungeon[i - 1][j] != 130
&& dungeon[i + 1][j] != 132 && dungeon[i - 1][j] != 132
&& dungeon[i + 1][j] != 133 && dungeon[i - 1][j] != 133
Expand All @@ -1126,13 +1130,15 @@ void FenceDoorFix()
}
}
if (dungeon[i][j] == 147) {
if (j > 0 && j < DMAXY - 1)
if (dungeon[i][j + 1] > 152 || dungeon[i][j + 1] < 130
|| dungeon[i][j - 1] > 152 || dungeon[i][j - 1] < 130) {
dungeon[i][j] = 7;
continue;
}
}
if (dungeon[i][j] == 147) {
if (j > 0 && j < DMAXY - 1)
if (dungeon[i][j + 1] != 131 && dungeon[i][j - 1] != 131
&& dungeon[i][j + 1] != 132 && dungeon[i][j - 1] != 132
&& dungeon[i][j + 1] != 133 && dungeon[i][j - 1] != 133
Expand Down Expand Up @@ -1281,14 +1287,14 @@ static void DRLG_L3Wood()
}
if (rt == 1) {
x1 = i;
// BUGFIX: Check `x1 >= 0` first (fixed)
while (x1 >= 0 && WoodHorizL(x1, j)) {
// BUGFIX: Check `x1 >= 0` first (fixed)
while (x1 >= 0 && WoodHorizL(x1, j)) {
x1--;
}
x1++;
x2 = i;
// BUGFIX: Check `x2 < DMAXX` first (fixed)
while (x2 < DMAXX && WoodHorizR(x2, j)) {
// BUGFIX: Check `x2 < DMAXX` first (fixed)
while (x2 < DMAXX && WoodHorizR(x2, j)) {
x2++;
}
x2--;
Expand Down

0 comments on commit e4a9d68

Please sign in to comment.