From b76d4338beea6a5a744ceed06fde134833d4ef14 Mon Sep 17 00:00:00 2001 From: nhmall Date: Mon, 9 Feb 2026 08:39:21 -0500 Subject: [PATCH] avoid a reported obuf reuse in use_misc() Report: https://github.com/NetHack/NetHack/issues/1486 Resolves #1486 --- src/muse.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/muse.c b/src/muse.c index 0f02778be..37334df7c 100644 --- a/src/muse.c +++ b/src/muse.c @@ -2520,7 +2520,7 @@ use_misc(struct monst *mtmp) int where_to = rn2(4); struct obj *obj = uwep; const char *hand; - char the_weapon[BUFSZ]; + char the_weapon[BUFSZ], hand_buf[BUFSZ]; if (!obj || !canletgo(obj, "") || (u.twoweap && canletgo(uswapwep, "") && rn2(2))) @@ -2532,10 +2532,12 @@ use_misc(struct monst *mtmp) hand = body_part(HAND); if (bimanual(obj)) hand = makeplural(hand); + (void) strncpy(hand_buf, hand, sizeof hand_buf - 1); + hand_buf[sizeof hand_buf - 1] = '\0'; if (vismon) pline_mon(mtmp, "%s flicks a bullwhip towards your %s!", - Monnam(mtmp), hand); + Monnam(mtmp), hand_buf); if (obj->otyp == HEAVY_IRON_BALL) { pline("%s fails to wrap around %s.", The_whip, the_weapon); return 1; @@ -2544,7 +2546,7 @@ use_misc(struct monst *mtmp) the_weapon); if (welded(obj)) { pline("%s welded to your %s%c", - !is_plural(obj) ? "It is" : "They are", hand, + !is_plural(obj) ? "It is" : "They are", hand_buf, !obj->bknown ? '!' : '.'); /* obj->bknown = 1; */ /* welded() takes care of this */ where_to = 0; @@ -2563,7 +2565,7 @@ use_misc(struct monst *mtmp) switch (where_to) { case 1: /* onto floor beneath mon */ pline_mon(mtmp, "%s yanks %s from your %s!", Monnam(mtmp), - the_weapon, hand); + the_weapon, hand_buf); place_object(obj, mtmp->mx, mtmp->my); break; case 2: /* onto floor beneath you */