From 576dd10bdd61765a2a9b3c21f7939aa5afd1c962 Mon Sep 17 00:00:00 2001 From: PatR Date: Wed, 24 Jan 2024 00:37:09 -0800 Subject: [PATCH] fix #K4088 and #K4089 - ring formatting +/-N for charged rings with known enchantment was clobbering the BUC formatting that had occurred earlier. #K4088 thought it was a problem with the implicit_cursed option; followup #K4089 from same user correctly pointed out that the problem was present for any BUC state. This is the same line of code that inadvertently omitted the space between +/-N and "ring of ". That was fixed by commit 1a2b2a8cae21ed10b4d0c04a288bf7c86f7b5cbe a couple of days ago. While in doname(), fix a potential issue calling corpse_xname(). That assigns a new value to gx.xnamep, clobbering the value that doname() relied on when it was first called (but doesn't look at again, so doesn't matter now but could conceivably in the future). --- doc/fixes3-7-0.txt | 2 ++ src/objnam.c | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index 532a4b454..ad61c7740 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -1845,6 +1845,8 @@ stacked pair of potions of healing in supply chest weighed same as one potion; weight updated as their stack was split; if close to an encumbrance threshold, new weight would trigger an encumbrance increase message, immediately followed a decrease message when the potion got used up +bounds checking for object name formatting inadvertently introduced a change + that hid BUC prefix for charged rings Fixes to 3.7.0-x Platform and/or Interface Problems Exposed Via git Repository diff --git a/src/objnam.c b/src/objnam.c index 98b77f9e5..246785e46 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -1435,7 +1435,7 @@ doname_base( Concat(bp, 0, " (lit)"); break; case RING_CLASS: - ring: + ring: /* normal rings reach here 'naturally'; meat ring jumps here */ if (obj->owornmask & W_RINGR) Concat(bp, 0, " (on right "); if (obj->owornmask & W_RINGL) @@ -1443,7 +1443,7 @@ doname_base( if (obj->owornmask & W_RING) /* either left or right */ ConcatF1(bp, 0,"%s)", body_part(HAND)); if (known && objects[obj->otyp].oc_charged) { - Sprintf(prefix, "%+d ", obj->spe); /* sitoa(obj->spe)+" " */ + Sprintf(eos(prefix), "%+d ", obj->spe); /* sitoa(obj->spe)+" " */ } break; case FOOD_CLASS: @@ -1455,11 +1455,17 @@ doname_base( "corpse" is already in the buffer returned by xname() */ unsigned cxarg = (((obj->quan != 1L) ? 0 : CXN_ARTICLE) | CXN_NOCORPSE); - char *cxstr = corpse_xname(obj, prefix, cxarg); + char *cxstr, *save_xnamep; + /* corpse_xname() sets xnamep; callers other than doname_base() + itself shouldn't care about xnamep (pointer to start of + current obuf[]) but keep it accurate anyway */ + save_xnamep = gx.xnamep; + cxstr = corpse_xname(obj, prefix, cxarg); Sprintf(prefix, "%s ", cxstr); /* avoid having doname(corpse) consume an extra obuf */ releaseobuf(cxstr); + gx.xnamep = save_xnamep; } else if (obj->otyp == EGG) { #if 0 /* corpses don't tell if they're stale either */ if (known && stale_egg(obj)) @@ -1472,9 +1478,9 @@ doname_base( if (obj->spe == 1) Concat(bp, 0, " (laid by you)"); } - } - if (obj->otyp == MEAT_RING) + } else if (obj->otyp == MEAT_RING) { goto ring; + } break; case BALL_CLASS: case CHAIN_CLASS: