From 490b60da4d160c776b48c7687e6077f6bb207666 Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 20 Nov 2023 00:29:16 -0800 Subject: [PATCH] whatis fix for boulders In the past couple of days the code for '/' and ';' to examine objects was changed to handle ROCK_CLASS differently (as part of revising looking at map spots showing the engraving symbol). It could potentially set up a static buffer in the object classes loop and then overwrite that when processing another class. I couldn't trigger any feedback anomalies, even when changing bouldersym to various values including class characters both before and after '`', but this redoes the suspect code to make it more robust. Also, refine the test for whether a screen symbol matches an object symbol. --- src/pager.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/pager.c b/src/pager.c index ceaf8655b..c92220114 100644 --- a/src/pager.c +++ b/src/pager.c @@ -1269,8 +1269,7 @@ do_screen_description( /* Now check for objects */ if (!iflags.terrainmode || (iflags.terrainmode & TER_OBJ) != 0) { - /* need a static buffer in case it gets returned as *firstmatch */ - static char oc_buf[40]; /* does not need to be in 'struct g' */ + const char *oc_ptr; nhsym bouldersym; j = SYM_BOULDER + SYM_OFF_X; @@ -1280,21 +1279,21 @@ do_screen_description( bouldersym = def_oc_syms[ROCK_CLASS].sym; for (i = 1; i < MAXOCLASSES; i++) { - if (sym == (looked ? gs.showsyms[i + SYM_OFF_O] - : def_oc_syms[i].sym) - || (i == ROCK_CLASS && (glyph_is_statue(glyph) - || sym == bouldersym))) { - Strcpy(oc_buf, def_oc_syms[i].explain); + if ((i != ROCK_CLASS) + ? (sym == (looked ? gs.showsyms[i + SYM_OFF_O] + : def_oc_syms[i].sym)) /* ROCK_CLASS is complicated; statues are displayed as the monster they depict rather than as S_rock; boulders might - be displayed as a custom symbol rather than as S_rock; - for added fun, engravings are shown with the same symbol + be displayed as a custom symbol rather than as S_rock */ + : (glyph_is_statue(glyph) || sym == bouldersym)) { + oc_ptr = def_oc_syms[i].explain; + /* for added fun, engravings are shown with the same symbol as S_rock which is why we want to shorten this */ - if (i == ROCK_CLASS && !strcmp(oc_buf, "boulder or statue")) { + if (i == ROCK_CLASS && !strcmp(oc_ptr, "boulder or statue")) { if (sym == bouldersym) - Strcpy(oc_buf, "boulder"); /* discard "or statue" */ + oc_ptr = "boulder"; /* discard "or statue" */ else if (glyph_is_statue(glyph)) - Strcpy(oc_buf, "statue"); /* discard "boulder or" */ + oc_ptr = "statue"; /* discard "boulder or" */ else if (looked) continue; /* discard both */ } @@ -1304,11 +1303,15 @@ do_screen_description( continue; } if (!found) { - Sprintf(out_str, "%s%s", prefix, an(oc_buf)); - *firstmatch = oc_buf; + Sprintf(out_str, "%s%s", prefix, an(oc_ptr)); + /* note: if the value assigned to *firstmatch ever + becomes dynamically constructed, it will need to be + copied into a static buffer; as of now, all alternate + values are string literals and implicitly static */ + *firstmatch = oc_ptr; found++; } else { - found += append_str(out_str, an(oc_buf)); + found += append_str(out_str, an(oc_ptr)); } } }