]> granicus.if.org Git - nethack/commitdiff
Fix infinite loop if god cannot fix your trouble
authorPasi Kallinen <paxed@alt.org>
Tue, 13 Oct 2015 17:36:36 +0000 (20:36 +0300)
committerPasi Kallinen <paxed@alt.org>
Tue, 13 Oct 2015 17:36:40 +0000 (20:36 +0300)
For example, if safe_teleds cannot land you in a safe spot,
because level is full of monsters.

src/pray.c

index b4aa9c2c095ecd43b526ef591b452ca51b9e5b96..deb046bc460a38755f6155ec9f60d678b25041a0 100644 (file)
@@ -904,6 +904,7 @@ aligntyp g_align;
             pat_on_head = 1;
     } else {
         int action, prayer_luck;
+        int tryct = 0;
 
         /* Negative luck is normally impossible here (can_pray() forces
            prayer failure in that situation), but it's possible for
@@ -936,7 +937,8 @@ aligntyp g_align;
         case 3:
             fix_worst_trouble(trouble);
         case 2:
-            while ((trouble = in_trouble()) > 0)
+            /* arbitrary number of tries */
+            while ((trouble = in_trouble()) > 0 && (++tryct < 10))
                 fix_worst_trouble(trouble);
             break;