From 185515e1c719c040f0fc3860859053d7dc6c092a Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sun, 11 Oct 2015 16:18:03 +0300 Subject: [PATCH] Fix infinite loop in makemon if no goodpos available If the level was full of monsters, goodpos never returns TRUE, and tryct would not get incremented. --- src/makemon.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/makemon.c b/src/makemon.c index 8afdb2777..cfe3959e1 100644 --- a/src/makemon.c +++ b/src/makemon.c @@ -967,15 +967,19 @@ register int mmflags; /* if caller wants random location, do it here */ if (x == 0 && y == 0) { - int tryct = 0; /* careful with bigrooms */ + int tryct = 200; /* careful with bigrooms */ + boolean good; struct monst fakemon; fakemon.data = ptr; /* set up for goodpos */ do { x = rn1(COLNO - 3, 2); y = rn2(ROWNO); - } while (!goodpos(x, y, ptr ? &fakemon : (struct monst *) 0, gpflags) - || (!in_mklev && tryct++ < 50 && cansee(x, y))); + if (!in_mklev && cansee(x,y)) tryct--; + good = goodpos(x, y, ptr ? &fakemon : (struct monst *) 0, gpflags); + } while (tryct && !good); + if (!good) + return ((struct monst *) 0); } else if (byyou && !in_mklev) { coord bypos;