From 0834d51482ea8e4fd3f3a015091dfaf895b96639 Mon Sep 17 00:00:00 2001 From: "nethack.allison" Date: Thu, 6 Nov 2003 02:16:22 +0000 Subject: [PATCH] mon name buffers Follow suit with what did for the object name buffers, so that this sort of statement can work correctly: pline("%s hits %s.", Monnam(mtmp), mon_nam(mtmp2)); --- doc/fixes35.0 | 1 + src/do_name.c | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/doc/fixes35.0 b/doc/fixes35.0 index 5087f0fd6..185c6ef9b 100644 --- a/doc/fixes35.0 +++ b/doc/fixes35.0 @@ -48,6 +48,7 @@ make it possible for the code to recognize your starting pet throughout the healers notice when a wand of undead turning revives a monster so the wand is then identified update display if bestowed a spellbook while unable to see invisible self +use small pool of static buffers for mon_nam() and Monnam() Platform- and/or Interface-Specific Fixes diff --git a/src/do_name.c b/src/do_name.c index 9d3cff73e..099d07a3c 100644 --- a/src/do_name.c +++ b/src/do_name.c @@ -6,9 +6,23 @@ STATIC_DCL void FDECL(do_oname, (struct obj *)); STATIC_DCL void FDECL(getpos_help, (BOOLEAN_P,const char *)); +STATIC_DCL char *NDECL(nextmbuf); extern const char what_is_an_unknown_object[]; /* from pager.c */ +#define NUMMBUF 5 + +/* manage a pool of BUFSZ buffers, so callers don't have to */ +STATIC_OVL char * +nextmbuf() +{ + static char NEARDATA bufs[NUMMBUF][BUFSZ]; + static int bufidx = 0; + + bufidx = (bufidx + 1) % NUMMBUF; + return bufs[bufidx]; +} + /* the response for '?' help request in getpos() */ STATIC_OVL void getpos_help(force, goal) @@ -579,11 +593,7 @@ int suppress; */ boolean called; { -#ifdef LINT /* static char buf[BUFSZ]; */ - char buf[BUFSZ]; -#else - static char buf[BUFSZ]; -#endif + char *buf = nextmbuf(); struct permonst *mdat = mtmp->data; boolean do_hallu, do_invis, do_it, do_saddle; boolean name_at_start, has_adjectives; @@ -606,7 +616,7 @@ boolean called; !(suppress & SUPPRESS_IT); do_saddle = !(suppress & SUPPRESS_SADDLE); - buf[0] = 0; + buf[0] = '\0'; /* unseen monsters, etc. Use "it" */ if (do_it) {