]> granicus.if.org Git - nethack/commitdiff
Fix segfault when the Wizard tried teleporting on the planes
authorPasi Kallinen <paxed@alt.org>
Mon, 14 Dec 2020 15:46:57 +0000 (17:46 +0200)
committerPasi Kallinen <paxed@alt.org>
Mon, 14 Dec 2020 15:51:16 +0000 (17:51 +0200)
The wizard of Yendor tried teleporting to the stairs on the
plane of Earth, but there are none there.

This was caused by the stairs structure reworking.

Fixes #422

src/teleport.c

index e5e34c5ae145d033605fc077f3907f3fbb25efa1..5c7b84964d94c757b0125b585b2b26a50a6bb4d4 100644 (file)
@@ -1284,7 +1284,6 @@ struct monst *mtmp; /* mx==0 implies migrating monster arrival */
 boolean suppress_impossible;
 {
     register int x, y, trycount;
-    stairway *stway;
 
     if (mtmp == u.usteed) {
         tele();
@@ -1292,19 +1291,19 @@ boolean suppress_impossible;
     }
 
     if (mtmp->iswiz && mtmp->mx) { /* Wizard, not just arriving */
+        stairway *stway;
+
         if (!In_W_tower(u.ux, u.uy, &u.uz)) {
             stway = stairway_find_forwiz(FALSE, TRUE);
-            x = stway->sx;
-            y = stway->sy;
         } else if (!stairway_find_forwiz(TRUE, FALSE)) { /* bottom level of tower */
             stway = stairway_find_forwiz(TRUE, TRUE);
-            x = stway->sx;
-            y = stway->sy;
         } else {
             stway = stairway_find_forwiz(TRUE, FALSE);
-            x = stway->sx;
-            y = stway->sy;
         }
+
+        x = stway ? stway->sx : 0;
+        y = stway ? stway->sy : 0;
+
         /* if the wiz teleports away to heal, try the up staircase,
            to block the player's escaping before he's healed
            (deliberately use `goodpos' rather than `rloc_pos_ok' here) */