Skip to content

Commit 968095a

Browse files
committed
Prevent endless loop in place_random_engraving()
1 parent ddc5123 commit 968095a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/mklev.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,7 @@ const int size; /* number of engravings in array */
19151915
xchar sx, sy;
19161916
char const *engraving = engravings[rn2(size)];
19171917

1918+
int trycount=0;
19181919
do {
19191920
if (Inhell || nroom <= 1) {
19201921
/* random placement in Gehennom or levels with no rooms */
@@ -1932,9 +1933,11 @@ const int size; /* number of engravings in array */
19321933
sy = somey(some_room);
19331934
}
19341935
}
1935-
} while (occupied(sx, sy));
1936+
} while (occupied(sx, sy) && (++trycount < 1000));
19361937

1937-
make_engr_at(sx, sy, engraving, 0L, BURN);
1938+
if (trycount < 1000) {
1939+
make_engr_at(sx, sy, engraving, 0L, BURN);
1940+
}
19381941
}
19391942

19401943
/*

0 commit comments

Comments
 (0)