]> granicus.if.org Git - nethack/commitdiff
shk segfault diagnostic workaround but not fix
authornhmall <mjnh@persona.ca>
Sun, 3 Jan 2016 16:33:03 +0000 (11:33 -0500)
committernhmall <mjnh@persona.ca>
Sun, 3 Jan 2016 16:33:03 +0000 (11:33 -0500)
 Changes to be committed:
modified:   src/shk.c

src/shk.c

index c8123b74affe8e8999c46f9d9f439124ca8991cf..ca3893b1fd4f0afe96696169cac333feaf5cecdd 100644 (file)
--- a/src/shk.c
+++ b/src/shk.c
@@ -1,4 +1,4 @@
-/* NetHack 3.6 shk.c   $NHDT-Date: 1450604649 2015/12/20 09:44:09 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.117 $ */
+/* NetHack 3.6 shk.c   $NHDT-Date: 1451838768 2016/01/03 16:32:48 $  $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.119 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -759,13 +759,26 @@ register char rmno;
         rmno >= ROOMOFFSET ? rooms[rmno - ROOMOFFSET].resident : 0;
 
     if (shkp) {
-        if (NOTANGRY(shkp)) {
-            if (ESHK(shkp)->surcharge)
-                pacify_shk(shkp);
+        if (has_eshk(shkp)) {
+            if (NOTANGRY(shkp)) {
+                if (ESHK(shkp)->surcharge)
+                    pacify_shk(shkp);
+            } else {
+                if (!ESHK(shkp)->surcharge)
+                    rile_shk(shkp);
+            }
         } else {
-            if (!ESHK(shkp)->surcharge)
-                rile_shk(shkp);
-        }
+            /* would have segfaulted on ESHK dereference previously */
+            impossible(
+             "shopkeeper career change? (rmno=%d, ROOMOFFSET=%d, mnum=%d, %s)",
+                (int)rmno, ROOMOFFSET, shkp->mnum,
+                has_mname(shkp) ? MNAME(shkp) : "anonymous"
+            );
+
+            /* not sure if this is appropriate, because it does nothing to
+               correct the underlying rooms[].resident issue but... */
+            return (struct monst *)0;
+       }
     }
     return shkp;
 }