]> granicus.if.org Git - nethack/commitdiff
wizard mode ^V crash in endgame
authornethack.rankin <nethack.rankin>
Sat, 13 Dec 2003 14:51:38 +0000 (14:51 +0000)
committernethack.rankin <nethack.rankin>
Sat, 13 Dec 2003 14:51:38 +0000 (14:51 +0000)
     Mentioned in passing in the newsgroup:  level teleporting in the
endgame--which is only possible in wizard mode--can crash if you're
confused.  The change to make confusion sometimes override teleport
control means that sometimes a random destination will be chosen, and
the routine to choose a random level can call rn2() with a value less
than 1 in the endgame, possibly resulting in attempt to divide by 0.

     There's something fishy about the min_/max_depth stuff for the
endgame, but I haven't attempted to figure that out.  This just makes
the random destination always be the current level when in the endgame
so that the problem can't come up.

doc/fixes34.4
src/teleport.c

index 59a309b8ea35ddbd21453c4983e78138ce02c33b..c0cbdfff4a416a38f554d99d54949cc4dcaeed3e 100644 (file)
@@ -4,6 +4,8 @@ General Fixes and Modified Features
 -----------------------------------
 fix "You hear The food ration tumbles downwards" for blinded pit dropping
 silver arrows weren't causing silver damage on some silver-haters when wielded
+wizard mode: avoid division by 0 crash for level teleport in the endgame if
+       confusion overrides teleport control
 
 
 Platform- and/or Interface-Specific Fixes
index 79e9178300bc8457ff93a2deded8b11a6bf158b9..99f344611184212c659d22c563ecf8624c4ab764 100644 (file)
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)teleport.c 3.4     2003/12/01      */
+/*     SCCS Id: @(#)teleport.c 3.4     2003/12/12      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -1222,7 +1222,8 @@ random_teleport_level()
        int nlev, max_depth, min_depth,
            cur_depth = (int)depth(&u.uz);
 
-       if (!rn2(5) || Is_knox(&u.uz))
+       /* [the endgame case can only occur in wizard mode] */
+       if (!rn2(5) || Is_knox(&u.uz) || In_endgame(&u.uz))
            return cur_depth;
 
        /* What I really want to do is as follows: