From b1dd8ac0930cbec39a337db890b68913e9d2bc23 Mon Sep 17 00:00:00 2001 From: "nethack.allison" Date: Mon, 10 Nov 2003 01:39:38 +0000 Subject: [PATCH] silver wands followup There was code higher up that could destroy the obj, so this eliminates any risk of trying to dereference a bad pointer in the deferred silver message by saving a copy of the name earlier on. --- src/uhitm.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/uhitm.c b/src/uhitm.c index 1a18afd77..ca6d94e30 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -554,8 +554,11 @@ int thrown; struct obj *monwep; char yourbuf[BUFSZ]; char unconventional[BUFSZ]; /* substituted for word "attack" in msg */ + char saved_oname[BUFSZ]; unconventional[0] = '\0'; + saved_oname[0] = '\0'; + wakeup(mon); if(!obj) { /* attack with bare hands */ if (mdat == &mons[PM_SHADE]) @@ -582,6 +585,7 @@ int thrown; } } } else { + Strcpy(saved_oname, cxname(obj)); if(obj->oclass == WEAPON_CLASS || is_weptool(obj) || obj->oclass == GEM_CLASS) { @@ -1043,11 +1047,11 @@ int thrown; fmt = "Your silver ring sears %s!"; else if (barehand_silver_rings == 2) fmt = "Your silver rings sear %s!"; - else if (silverobj) { + else if (silverobj && saved_oname[0]) { Sprintf(silverobjbuf, "Your %s%s %s %%s!", - strstri(xname(obj), "silver") ? + strstri(saved_oname, "silver") ? "" : "silver ", - xname(obj), otense(obj, "sear")); + saved_oname, vtense(saved_oname, "sear")); fmt = silverobjbuf; } else fmt = "The silver sears %s!"; -- 2.40.0