From: Michael Meyer Date: Wed, 5 May 2021 21:57:53 +0000 (-0400) Subject: Fix: uninitialized buffer in mhitm theft feedback X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9ba4b6ad4d0c4e62e803e760ebd445ddb5f7386a;p=nethack Fix: uninitialized buffer in mhitm theft feedback 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 " 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. --- diff --git a/src/uhitm.c b/src/uhitm.c index 84da9f0f8..f777bed4c 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -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);