From: PatR Date: Tue, 4 Jul 2017 21:47:00 +0000 (-0700) Subject: releaseobuf() fix X-Git-Tag: NetHack-3.6.1_RC01~455 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7a8559a34d238ccfd44f44f5dadbd11c1d0bec58;p=nethack 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. --- diff --git a/src/objnam.c b/src/objnam.c index e583d7a5c..4648649e3 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -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);