]> granicus.if.org Git - nethack/commitdiff
Fix: uninitialized buffer in mhitm theft feedback
authorMichael Meyer <me@entrez.cc>
Wed, 5 May 2021 21:57:53 +0000 (17:57 -0400)
committerPasi Kallinen <paxed@alt.org>
Thu, 6 May 2021 16:15:56 +0000 (19:15 +0300)
If a monster with a theft attack (nymph or leprechaun) stole something
from an invisible monster (e.g. while under the influence of conflict),
and the attacking monster was not itself invisible, the monster name
buffer used when printing the "<foo> suddenly disappears!" message would
be used while still uninitialized.  The attacking monster's name was
only copied into the buffer if the defending monster was visible, but
would be used regardless to print the pline if the attacking monster was
visible and teleported away successfully after the attack.

src/uhitm.c

index 84da9f0f89154ef63adb5ba9c2707b8a82965375..f777bed4c22459b096f937029b74ff8eb2e9f875 100644 (file)
@@ -2284,8 +2284,8 @@ mhitm_ad_sgld(struct monst *magr, struct attack *mattk, struct monst *mdef,
             add_to_minv(magr, gold);
         }
         mdef->mstrategy &= ~STRAT_WAITFORU;
+        Strcpy(buf, Monnam(magr));
         if (g.vis && canseemon(mdef)) {
-            Strcpy(buf, Monnam(magr));
             pline("%s steals some gold from %s.", buf, mon_nam(mdef));
         }
         if (!tele_restrict(magr)) {
@@ -3965,8 +3965,8 @@ mhitm_ad_sedu(struct monst *magr, struct attack *mattk, struct monst *mdef,
             if (g.vis)
                 Strcpy(onambuf, doname(obj));
             (void) add_to_minv(magr, obj);
+            Strcpy(buf, Monnam(magr));
             if (g.vis && canseemon(mdef)) {
-                Strcpy(buf, Monnam(magr));
                 pline("%s steals %s from %s!", buf, onambuf, mdefnambuf);
             }
             possibly_unwield(mdef, FALSE);