releaseobuf() fix

The object name formatting routines operate using a pool of buffers to
hold intermediate and/or final result.  Some routines consume multiple
intermediate buffers, so use releaseobj() to try to reuse just one in
order to avoid churning through too many and maybe clobbering live
data.  It worked as intended for routines that use nextobuf() directly
but wouldn't haved worked right for xname(), also doname() and other
xname() callers.  This fixes that.

There have never been any reports of garbled messages which could be
traced to clobbering of formatted object names, so this fix is mostly
academic.
This commit is contained in:
PatR
2017-07-04 14:47:00 -07:00
parent ca84c8e0ff
commit 7a8559a34d

View File

@@ -90,8 +90,12 @@ releaseobuf(bufp)
char *bufp;
{
/* caller may not know whether bufp is the most recently allocated
buffer; if it isn't, do nothing */
if (bufp == obufs[obufidx])
buffer; if it isn't, do nothing; note that because of the somewhat
obscure PREFIX handling for object name formatting by xname(),
the pointer our caller has and is passing to us might be into the
middle of an obuf rather than the address returned by nextobuf() */
if (bufp >= obufs[obufidx]
&& bufp < obufs[obufidx] + sizeof obufs[obufidx]) /* obufs[][BUFSZ] */
obufidx = (obufidx - 1 + NUMOBUF) % NUMOBUF;
}
@@ -100,11 +104,11 @@ obj_typename(otyp)
register int otyp;
{
char *buf = nextobuf();
register struct objclass *ocl = &objects[otyp];
register const char *actualn = OBJ_NAME(*ocl);
register const char *dn = OBJ_DESCR(*ocl);
register const char *un = ocl->oc_uname;
register int nn = ocl->oc_name_known;
struct objclass *ocl = &objects[otyp];
const char *actualn = OBJ_NAME(*ocl);
const char *dn = OBJ_DESCR(*ocl);
const char *un = ocl->oc_uname;
int nn = ocl->oc_name_known;
if (Role_if(PM_SAMURAI) && Japanese_item_name(otyp))
actualn = Japanese_item_name(otyp);