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.
This commit is contained in:
nethack.allison
2003-11-10 01:39:38 +00:00
parent 800baf8771
commit b1dd8ac093
+7 -3
View File
@@ -554,8 +554,11 @@ int thrown;
struct obj *monwep; struct obj *monwep;
char yourbuf[BUFSZ]; char yourbuf[BUFSZ];
char unconventional[BUFSZ]; /* substituted for word "attack" in msg */ char unconventional[BUFSZ]; /* substituted for word "attack" in msg */
char saved_oname[BUFSZ];
unconventional[0] = '\0'; unconventional[0] = '\0';
saved_oname[0] = '\0';
wakeup(mon); wakeup(mon);
if(!obj) { /* attack with bare hands */ if(!obj) { /* attack with bare hands */
if (mdat == &mons[PM_SHADE]) if (mdat == &mons[PM_SHADE])
@@ -582,6 +585,7 @@ int thrown;
} }
} }
} else { } else {
Strcpy(saved_oname, cxname(obj));
if(obj->oclass == WEAPON_CLASS || is_weptool(obj) || if(obj->oclass == WEAPON_CLASS || is_weptool(obj) ||
obj->oclass == GEM_CLASS) { obj->oclass == GEM_CLASS) {
@@ -1043,11 +1047,11 @@ int thrown;
fmt = "Your silver ring sears %s!"; fmt = "Your silver ring sears %s!";
else if (barehand_silver_rings == 2) else if (barehand_silver_rings == 2)
fmt = "Your silver rings sear %s!"; fmt = "Your silver rings sear %s!";
else if (silverobj) { else if (silverobj && saved_oname[0]) {
Sprintf(silverobjbuf, "Your %s%s %s %%s!", Sprintf(silverobjbuf, "Your %s%s %s %%s!",
strstri(xname(obj), "silver") ? strstri(saved_oname, "silver") ?
"" : "silver ", "" : "silver ",
xname(obj), otense(obj, "sear")); saved_oname, vtense(saved_oname, "sear"));
fmt = silverobjbuf; fmt = silverobjbuf;
} else } else
fmt = "The silver sears %s!"; fmt = "The silver sears %s!";