]> granicus.if.org Git - nethack/commitdiff
silver wands followup
authornethack.allison <nethack.allison>
Mon, 10 Nov 2003 01:39:38 +0000 (01:39 +0000)
committernethack.allison <nethack.allison>
Mon, 10 Nov 2003 01:39:38 +0000 (01:39 +0000)
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

index 1a18afd77d319ae514586325cfd2904d4109907a..ca6d94e303900947d56ada93462fc40b7fc51dc0 100644 (file)
@@ -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!";