From 5c39096fd4bf260528e0ba7144a79b6242898580 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Tue, 28 Mar 2023 19:49:49 +0300 Subject: [PATCH] Prevent infinite loop making Medusa statues While fuzzing, the game got stuck here trying to generate a random stoneable monster for a Medusa level statue. I didn't investigate deeper why it failed to find a matching monster type. --- src/mkmaze.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/mkmaze.c b/src/mkmaze.c index 3d74edd2d..c423e0ff6 100644 --- a/src/mkmaze.c +++ b/src/mkmaze.c @@ -593,8 +593,11 @@ fixup_special(void) x = somex(croom); y = somey(croom); if (goodpos(x, y, (struct monst *) 0, 0)) { + int tryct2 = 0; + otmp = mk_tt_object(STATUE, x, y); - while (otmp && (poly_when_stoned(&mons[otmp->corpsenm]) + while (++tryct2 < 100 && otmp + && (poly_when_stoned(&mons[otmp->corpsenm]) || pm_resistance(&mons[otmp->corpsenm], MR_STONE))) { /* set_corpsenm() handles weight too */ @@ -610,8 +613,10 @@ fixup_special(void) mkcorpstat(STATUE, (struct monst *) 0, (struct permonst *) 0, somex(croom), somey(croom), CORPSTAT_NONE); if (otmp) { - while (pm_resistance(&mons[otmp->corpsenm], MR_STONE) - || poly_when_stoned(&mons[otmp->corpsenm])) { + tryct = 0; + while (++tryct < 100 + && (pm_resistance(&mons[otmp->corpsenm], MR_STONE) + || poly_when_stoned(&mons[otmp->corpsenm]))) { /* set_corpsenm() handles weight too */ set_corpsenm(otmp, rndmonnum()); }