]> granicus.if.org Git - nethack/commitdiff
fix #H4153 - killed by kicking something weird
authorPatR <rankin@nethack.org>
Sun, 3 Jan 2016 08:36:31 +0000 (00:36 -0800)
committerPatR <rankin@nethack.org>
Sun, 3 Jan 2016 08:36:31 +0000 (00:36 -0800)
Steps to make sure 'kickedobj' didn't end up as a stale pointer
prevented it from being around to format the reason for death when
a kicking attempt was fatal.

doc/fixes36.1
src/dokick.c

index 3cc5261f68762e4dff41193da08ea62e572129bc..e7584feb4b4e894d8d497b62901ec00e07e94f5b 100644 (file)
@@ -79,6 +79,7 @@ when a pet moves reluctantly, name the top item of the pile it is reluctant
        to step on if the hero sees or remembers any object(s) at that spot
 ensure sufficient messages are given to clarify the transition from detected 
        vampire bats to fog clouds in Vlad's tower
+fix "killing by kicking something weird" when kicking an object causes death
 
 
 Platform- and/or Interface-Specific Fixes
index ca4e2a6bc2225e055e0e1cba34aa0bd2e2769f1e..7515f6fdafd9e44acdc5d14c00b133ebcf08a82a 100644 (file)
@@ -20,9 +20,9 @@ STATIC_DCL void FDECL(kickdmg, (struct monst *, BOOLEAN_P));
 STATIC_DCL boolean FDECL(maybe_kick_monster, (struct monst *,
                                               XCHAR_P, XCHAR_P));
 STATIC_DCL void FDECL(kick_monster, (struct monst *, XCHAR_P, XCHAR_P));
-STATIC_DCL int FDECL(kick_object, (XCHAR_P, XCHAR_P));
+STATIC_DCL int FDECL(kick_object, (XCHAR_P, XCHAR_P, char *));
 STATIC_DCL int FDECL(really_kick_object, (XCHAR_P, XCHAR_P));
-STATIC_DCL char *FDECL(kickstr, (char *));
+STATIC_DCL char *FDECL(kickstr, (char *, const char *));
 STATIC_DCL void FDECL(otransit_msg, (struct obj *, BOOLEAN_P, long));
 STATIC_DCL void FDECL(drop_to, (coord *, SCHAR_P));
 
@@ -463,15 +463,18 @@ xchar x, y; /* coordinates where object was before the impact, not after */
 
 /* jacket around really_kick_object */
 STATIC_OVL int
-kick_object(x, y)
+kick_object(x, y, kickobjnam)
 xchar x, y;
+char *kickobjnam;
 {
     int res = 0;
 
+    *kickobjnam = '\0';
     /* if a pile, the "top" object gets kicked */
     kickedobj = level.objects[x][y];
     if (kickedobj) {
         /* kick object; if doing is fatal, done() will clean up kickedobj */
+        Strcpy(kickobjnam, killer_xname(kickedobj)); /* matters iff res==0 */
         res = really_kick_object(x, y);
         kickedobj = (struct obj *) 0;
     }
@@ -707,13 +710,14 @@ xchar x, y;
 
 /* cause of death if kicking kills kicker */
 STATIC_OVL char *
-kickstr(buf)
+kickstr(buf, kickobjnam)
 char *buf;
+const char *kickobjnam;
 {
     const char *what;
 
-    if (kickedobj)
-        what = killer_xname(kickedobj);
+    if (*kickobjnam)
+        what = kickobjnam;
     else if (maploc == &nowhere)
         what = "nothing";
     else if (IS_DOOR(maploc->typ))
@@ -755,8 +759,9 @@ dokick()
     int dmg = 0, glyph, oldglyph = -1;
     register struct monst *mtmp;
     boolean no_kick = FALSE;
-    char buf[BUFSZ];
+    char buf[BUFSZ], kickobjnam[BUFSZ];
 
+    kickobjnam[0] = '\0';
     if (nolimbs(youmonst.data) || slithy(youmonst.data)) {
         You("have no legs to kick with.");
         no_kick = TRUE;
@@ -948,7 +953,7 @@ dokick()
 
     if (OBJ_AT(x, y) && (!Levitation || Is_airlevel(&u.uz)
                          || Is_waterlevel(&u.uz) || sobj_at(BOULDER, x, y))) {
-        if (kick_object(x, y)) {
+        if (kick_object(x, y, kickobjnam)) {
             if (Is_airlevel(&u.uz))
                 hurtle(-u.dx, -u.dy, 1, TRUE); /* assume it's light */
             return 1;
@@ -1211,7 +1216,7 @@ dokick()
             if (!rn2(3))
                 set_wounded_legs(RIGHT_SIDE, 5 + rnd(5));
             dmg = rnd(ACURR(A_CON) > 15 ? 3 : 5);
-            losehp(Maybe_Half_Phys(dmg), kickstr(buf), KILLED_BY);
+            losehp(Maybe_Half_Phys(dmg), kickstr(buf, kickobjnam), KILLED_BY);
             if (Is_airlevel(&u.uz) || Levitation)
                 hurtle(-u.dx, -u.dy, rn1(2, 4), TRUE); /* assume it's heavy */
             return 1;