avoid a reported obuf reuse in use_misc()

Report: https://github.com/NetHack/NetHack/issues/1486

Resolves #1486
This commit is contained in:
nhmall
2026-02-09 08:39:21 -05:00
parent 4b30e3fab8
commit b76d4338be

View File

@@ -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 */