From: Pasi Kallinen Date: Mon, 14 Dec 2020 15:46:57 +0000 (+0200) Subject: Fix segfault when the Wizard tried teleporting on the planes X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=480c2539331df1e9c4ed2c3a2f68e5c3821cf4f4;p=nethack Fix segfault when the Wizard tried teleporting on the planes 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 --- diff --git a/src/teleport.c b/src/teleport.c index e5e34c5ae..5c7b84964 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -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) */