From c92a3b065338c92411eaf440b0c4d9adc4ad2d55 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 27 Aug 2022 08:23:24 -0400 Subject: [PATCH] fix glyph_to_cmap() odd macro results Some discrepencies between glyph_is_cmap and glyph_to_cmap arose after b14b830b because the change resulted in glyph_is_cmap matching on zap beams which weren't accounted for in the glyph_to_cmap macro. It is unlikely that glyph_to_cmap will ever be used on such a glyph, but at least have glyph_to_cmap return a sane value rather than drop through to the last-resort value (currently NO_GLYPH) which is far outside the range of the defsyms[] array indices. --- include/display.h | 44 +++++++++++++++++++++++--------------------- src/cmd.c | 7 +++++++ 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/include/display.h b/include/display.h index ab69aaece..a427d1e1b 100644 --- a/include/display.h +++ b/include/display.h @@ -711,27 +711,29 @@ enum glyph_offsets { && (glyph) < (GLYPH_CMAP_C_OFF + ((S_goodpos - S_digbeam) + 1))) #define glyph_to_cmap(glyph) \ - (((glyph) == GLYPH_CMAP_STONE_OFF) \ - ? S_stone \ - : glyph_is_cmap_main(glyph) \ - ? (((glyph) - GLYPH_CMAP_MAIN_OFF) + S_vwall) \ - : glyph_is_cmap_mines(glyph) \ - ? (((glyph) - GLYPH_CMAP_MINES_OFF) + S_vwall) \ - : glyph_is_cmap_gehennom(glyph) \ - ? (((glyph) - GLYPH_CMAP_GEH_OFF) + S_vwall) \ - : glyph_is_cmap_knox(glyph) \ - ? (((glyph) - GLYPH_CMAP_KNOX_OFF) + S_vwall) \ - : glyph_is_cmap_sokoban(glyph) \ - ? (((glyph) - GLYPH_CMAP_SOKO_OFF) + S_vwall) \ - : glyph_is_cmap_a(glyph) \ - ? (((glyph) - GLYPH_CMAP_A_OFF) + S_ndoor) \ - : glyph_is_cmap_altar(glyph) \ - ? (S_altar) \ - : glyph_is_cmap_b(glyph) \ - ? (((glyph) - GLYPH_CMAP_B_OFF) + S_grave) \ - : glyph_is_cmap_c(glyph) \ - ? (((glyph) - GLYPH_CMAP_C_OFF) + S_digbeam) \ - : NO_GLYPH) + (((glyph) == GLYPH_CMAP_STONE_OFF) \ + ? S_stone \ + : glyph_is_cmap_main(glyph) \ + ? (((glyph) - GLYPH_CMAP_MAIN_OFF) + S_vwall) \ + : glyph_is_cmap_mines(glyph) \ + ? (((glyph) - GLYPH_CMAP_MINES_OFF) + S_vwall) \ + : glyph_is_cmap_gehennom(glyph) \ + ? (((glyph) - GLYPH_CMAP_GEH_OFF) + S_vwall) \ + : glyph_is_cmap_knox(glyph) \ + ? (((glyph) - GLYPH_CMAP_KNOX_OFF) + S_vwall) \ + : glyph_is_cmap_sokoban(glyph) \ + ? (((glyph) - GLYPH_CMAP_SOKO_OFF) + S_vwall) \ + : glyph_is_cmap_a(glyph) \ + ? (((glyph) - GLYPH_CMAP_A_OFF) + S_ndoor) \ + : glyph_is_cmap_altar(glyph) \ + ? (S_altar) \ + : glyph_is_cmap_b(glyph) \ + ? (((glyph) - GLYPH_CMAP_B_OFF) + S_grave) \ + : glyph_is_cmap_c(glyph) \ + ? (((glyph) - GLYPH_CMAP_C_OFF) + S_digbeam) \ + : glyph_is_cmap_zap(glyph) \ + ? ((((glyph) - GLYPH_ZAP_OFF) % 4) + S_vbeam) \ + : NO_GLYPH) #define glyph_to_swallow(glyph) \ (glyph_is_swallow(glyph) ? (((glyph) - GLYPH_SWALLOW_OFF) & 0x7) : 0) diff --git a/src/cmd.c b/src/cmd.c index 3e875eef3..917bb3127 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -4026,6 +4026,13 @@ wiz_display_macros(void) glyph, test); putstr(win, 0, buf); } + if (glyph_is_cmap_zap(glyph) + && !(test >= S_vbeam && test <= S_rslant)) { + Sprintf(buf, + "glyph_is_zap(glyph=%d) returned non-zap cmap %d", + glyph, test); + putstr(win, 0, buf); + } /* check against defsyms array subscripts */ if (test < 0 || test >= SIZE(defsyms)) { if (!trouble++)