From: PatR Date: Sun, 3 Jan 2016 08:36:31 +0000 (-0800) Subject: fix #H4153 - killed by kicking something weird X-Git-Tag: NetHack-3.6.1_RC01~1078 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f279a9ec0db33edf45ad32c8ddad127b6fe8cb67;p=nethack fix #H4153 - killed by kicking something weird 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. --- diff --git a/doc/fixes36.1 b/doc/fixes36.1 index 3cc5261f6..e7584feb4 100644 --- a/doc/fixes36.1 +++ b/doc/fixes36.1 @@ -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 diff --git a/src/dokick.c b/src/dokick.c index ca4e2a6bc..7515f6fda 100644 --- a/src/dokick.c +++ b/src/dokick.c @@ -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;