]> granicus.if.org Git - nethack/commitdiff
Prevent a segfault with leashed vanished monster
authorPasi Kallinen <paxed@alt.org>
Thu, 19 Jan 2017 17:46:37 +0000 (19:46 +0200)
committerPasi Kallinen <paxed@alt.org>
Thu, 19 Jan 2017 17:49:19 +0000 (19:49 +0200)
It's apparently somehow possible to have a leash "attached" to
a monster not present on the current level. Complain instead of
segfaulting. (This is a post-3.6.0 bug)

src/objnam.c

index af3cc25118e637af52d59a73481e5b16458f4999..bb0c91a448c00739c54e203b0e1c57f90d470396 100644 (file)
@@ -912,8 +912,15 @@ unsigned doname_flags;
             break;
         }
         if (obj->otyp == LEASH && obj->leashmon != 0) {
-            Sprintf(eos(bp), " (attached to %s)",
-                    a_monnam(find_mid(obj->leashmon, FM_FMON)));
+            struct monst *mlsh = find_mid(obj->leashmon, FM_FMON);
+
+            if (!mlsh) {
+                impossible("leashed monster not on this level");
+                obj->leashmon = 0;
+            } else {
+                Sprintf(eos(bp), " (attached to %s)",
+                        a_monnam(mlsh));
+            }
             break;
         }
         if (obj->otyp == CANDELABRUM_OF_INVOCATION) {