return legal indexes for some display.h macros
Some static analyzers flagged the last-resort values as out of bounds (which they were). There's a small number of other complaint-suppression items in here too, but nothing drastic.
This commit is contained in:
+6
-3
@@ -710,6 +710,7 @@ enum glyph_offsets {
|
|||||||
((glyph) >= GLYPH_CMAP_STONE_OFF \
|
((glyph) >= GLYPH_CMAP_STONE_OFF \
|
||||||
&& (glyph) < (GLYPH_CMAP_C_OFF + ((S_goodpos - S_digbeam) + 1)))
|
&& (glyph) < (GLYPH_CMAP_C_OFF + ((S_goodpos - S_digbeam) + 1)))
|
||||||
|
|
||||||
|
/* final MAXPCHARS is legal array index because of trailing fencepost entry */
|
||||||
#define glyph_to_cmap(glyph) \
|
#define glyph_to_cmap(glyph) \
|
||||||
(((glyph) == GLYPH_CMAP_STONE_OFF) \
|
(((glyph) == GLYPH_CMAP_STONE_OFF) \
|
||||||
? S_stone \
|
? S_stone \
|
||||||
@@ -733,7 +734,7 @@ enum glyph_offsets {
|
|||||||
? (((glyph) - GLYPH_CMAP_C_OFF) + S_digbeam) \
|
? (((glyph) - GLYPH_CMAP_C_OFF) + S_digbeam) \
|
||||||
: glyph_is_cmap_zap(glyph) \
|
: glyph_is_cmap_zap(glyph) \
|
||||||
? ((((glyph) - GLYPH_ZAP_OFF) % 4) + S_vbeam) \
|
? ((((glyph) - GLYPH_ZAP_OFF) % 4) + S_vbeam) \
|
||||||
: NO_GLYPH)
|
: MAXPCHARS)
|
||||||
|
|
||||||
#define glyph_to_swallow(glyph) \
|
#define glyph_to_swallow(glyph) \
|
||||||
(glyph_is_swallow(glyph) ? (((glyph) - GLYPH_SWALLOW_OFF) & 0x7) : 0)
|
(glyph_is_swallow(glyph) ? (((glyph) - GLYPH_SWALLOW_OFF) & 0x7) : 0)
|
||||||
@@ -779,6 +780,7 @@ enum glyph_offsets {
|
|||||||
|| glyph_is_ridden_monster(glyph) || glyph_is_detected_monster(glyph))
|
|| glyph_is_ridden_monster(glyph) || glyph_is_detected_monster(glyph))
|
||||||
#define glyph_is_invisible(glyph) ((glyph) == GLYPH_INVISIBLE)
|
#define glyph_is_invisible(glyph) ((glyph) == GLYPH_INVISIBLE)
|
||||||
|
|
||||||
|
/* final NUMMONS is legal array index because of trailing fencepost entry */
|
||||||
#define glyph_to_mon(glyph) \
|
#define glyph_to_mon(glyph) \
|
||||||
(glyph_is_normal_female_monster(glyph) \
|
(glyph_is_normal_female_monster(glyph) \
|
||||||
? ((glyph) - GLYPH_MON_FEM_OFF) \
|
? ((glyph) - GLYPH_MON_FEM_OFF) \
|
||||||
@@ -796,7 +798,7 @@ enum glyph_offsets {
|
|||||||
? ((glyph) - GLYPH_RIDDEN_FEM_OFF) \
|
? ((glyph) - GLYPH_RIDDEN_FEM_OFF) \
|
||||||
: glyph_is_ridden_male_monster(glyph) \
|
: glyph_is_ridden_male_monster(glyph) \
|
||||||
? ((glyph) - GLYPH_RIDDEN_MALE_OFF) \
|
? ((glyph) - GLYPH_RIDDEN_MALE_OFF) \
|
||||||
: NO_GLYPH)
|
: NUMMONS)
|
||||||
|
|
||||||
#define obj_is_piletop(obj) \
|
#define obj_is_piletop(obj) \
|
||||||
((obj)->where == OBJ_FLOOR \
|
((obj)->where == OBJ_FLOOR \
|
||||||
@@ -876,6 +878,7 @@ enum glyph_offsets {
|
|||||||
? (GLYPH_BODY_OFF))) \
|
? (GLYPH_BODY_OFF))) \
|
||||||
: ((int) (obj)->otyp + GLYPH_OBJ_OFF))))
|
: ((int) (obj)->otyp + GLYPH_OBJ_OFF))))
|
||||||
|
|
||||||
|
/* final NUM_OBJECTS is legal array idx because of trailing fencepost entry */
|
||||||
#define glyph_to_obj(glyph) \
|
#define glyph_to_obj(glyph) \
|
||||||
(glyph_is_body(glyph) ? CORPSE \
|
(glyph_is_body(glyph) ? CORPSE \
|
||||||
: glyph_is_statue(glyph) ? STATUE \
|
: glyph_is_statue(glyph) ? STATUE \
|
||||||
@@ -883,7 +886,7 @@ enum glyph_offsets {
|
|||||||
? ((glyph) - (glyph_is_normal_piletop_obj(glyph) \
|
? ((glyph) - (glyph_is_normal_piletop_obj(glyph) \
|
||||||
? GLYPH_OBJ_PILETOP_OFF \
|
? GLYPH_OBJ_PILETOP_OFF \
|
||||||
: GLYPH_OBJ_OFF)) \
|
: GLYPH_OBJ_OFF)) \
|
||||||
: NO_GLYPH)
|
: NUM_OBJECTS)
|
||||||
|
|
||||||
#define glyph_to_body_corpsenm(glyph) \
|
#define glyph_to_body_corpsenm(glyph) \
|
||||||
(glyph_is_body_piletop(glyph) \
|
(glyph_is_body_piletop(glyph) \
|
||||||
|
|||||||
+1
-1
@@ -160,7 +160,7 @@ struct symset_customization {
|
|||||||
};
|
};
|
||||||
#endif /* ENHANCED_SYMBOLS */
|
#endif /* ENHANCED_SYMBOLS */
|
||||||
|
|
||||||
extern const struct symdef defsyms[MAXPCHARS]; /* defaults */
|
extern const struct symdef defsyms[MAXPCHARS + 1]; /* defaults */
|
||||||
#define WARNCOUNT 6 /* number of different warning levels */
|
#define WARNCOUNT 6 /* number of different warning levels */
|
||||||
extern const struct symdef def_warnsyms[WARNCOUNT];
|
extern const struct symdef def_warnsyms[WARNCOUNT];
|
||||||
#define SYMHANDLING(ht) (g.symset[g.currentgraphics].handling == (ht))
|
#define SYMHANDLING(ht) (g.symset[g.currentgraphics].handling == (ht))
|
||||||
|
|||||||
+1
-2
@@ -3161,13 +3161,12 @@ static boolean
|
|||||||
find_poleable_mon(coord *pos, int min_range, int max_range)
|
find_poleable_mon(coord *pos, int min_range, int max_range)
|
||||||
{
|
{
|
||||||
struct monst *mtmp;
|
struct monst *mtmp;
|
||||||
coord mpos;
|
coord mpos = { 0, 0 }; /* no candidate location yet */
|
||||||
boolean impaired;
|
boolean impaired;
|
||||||
coordxy x, y, lo_x, hi_x, lo_y, hi_y, rt;
|
coordxy x, y, lo_x, hi_x, lo_y, hi_y, rt;
|
||||||
int glyph;
|
int glyph;
|
||||||
|
|
||||||
impaired = (Confusion || Stunned || Hallucination);
|
impaired = (Confusion || Stunned || Hallucination);
|
||||||
mpos.x = mpos.y = 0; /* no candidate location yet */
|
|
||||||
rt = isqrt(max_range);
|
rt = isqrt(max_range);
|
||||||
lo_x = max(u.ux - rt, 1), hi_x = min(u.ux + rt, COLNO - 1);
|
lo_x = max(u.ux - rt, 1), hi_x = min(u.ux + rt, COLNO - 1);
|
||||||
lo_y = max(u.uy - rt, 0), hi_y = min(u.uy + rt, ROWNO - 1);
|
lo_y = max(u.uy - rt, 0), hi_y = min(u.uy + rt, ROWNO - 1);
|
||||||
|
|||||||
+6
-4
@@ -1075,9 +1075,9 @@ tmp_at(coordxy x, coordxy y)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tglyph)
|
if (!tglyph) {
|
||||||
panic("tmp_at: tglyph not initialized");
|
panic("tmp_at: tglyph not initialized");
|
||||||
|
} else {
|
||||||
switch (x) {
|
switch (x) {
|
||||||
case DISP_CHANGE:
|
case DISP_CHANGE:
|
||||||
tglyph->glyph = y;
|
tglyph->glyph = y;
|
||||||
@@ -1144,7 +1144,8 @@ tmp_at(coordxy x, coordxy y)
|
|||||||
tglyph->saved[tglyph->sidx].y = y;
|
tglyph->saved[tglyph->sidx].y = y;
|
||||||
tglyph->sidx += 1;
|
tglyph->sidx += 1;
|
||||||
} else { /* DISP_FLASH/ALWAYS */
|
} else { /* DISP_FLASH/ALWAYS */
|
||||||
if (tglyph->sidx) { /* not first call, so reset previous pos */
|
if (tglyph
|
||||||
|
->sidx) { /* not first call, so reset previous pos */
|
||||||
newsym(tglyph->saved[0].x, tglyph->saved[0].y);
|
newsym(tglyph->saved[0].x, tglyph->saved[0].y);
|
||||||
tglyph->sidx = 0; /* display is presently up to date */
|
tglyph->sidx = 0; /* display is presently up to date */
|
||||||
}
|
}
|
||||||
@@ -1158,7 +1159,8 @@ tmp_at(coordxy x, coordxy y)
|
|||||||
show_glyph(x, y, tglyph->glyph); /* show it */
|
show_glyph(x, y, tglyph->glyph); /* show it */
|
||||||
flush_screen(0); /* make sure it shows up */
|
flush_screen(0); /* make sure it shows up */
|
||||||
break;
|
break;
|
||||||
} /* end case */
|
} /* end switch */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+7
-2
@@ -66,10 +66,15 @@ const struct symdef def_warnsyms[WARNCOUNT] = {
|
|||||||
* parsing other.txt because some of the useful tile names don't exist
|
* parsing other.txt because some of the useful tile names don't exist
|
||||||
* within NetHack itself.
|
* within NetHack itself.
|
||||||
*/
|
*/
|
||||||
const struct symdef defsyms[MAXPCHARS] = {
|
const struct symdef defsyms[MAXPCHARS + 1] = {
|
||||||
#define PCHAR_DRAWING
|
#define PCHAR_DRAWING
|
||||||
#include "defsym.h"
|
#include "defsym.h"
|
||||||
#undef PCHAR_DRAWING
|
#undef PCHAR_DRAWING
|
||||||
|
{ 0, NULL
|
||||||
|
#ifdef TEXTCOLOR
|
||||||
|
, NO_COLOR
|
||||||
|
#endif
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* default rogue level symbols */
|
/* default rogue level symbols */
|
||||||
@@ -130,7 +135,7 @@ def_char_is_furniture(char ch)
|
|||||||
int i;
|
int i;
|
||||||
boolean furniture = FALSE;
|
boolean furniture = FALSE;
|
||||||
|
|
||||||
for (i = 0; i < SIZE(defsyms); ++i) {
|
for (i = 0; i < MAXPCHARS; ++i) {
|
||||||
if (!furniture) {
|
if (!furniture) {
|
||||||
if (!strncmp(defsyms[i].explanation, first_furniture, 5))
|
if (!strncmp(defsyms[i].explanation, first_furniture, 5))
|
||||||
furniture = TRUE;
|
furniture = TRUE;
|
||||||
|
|||||||
+1
-1
@@ -62,7 +62,7 @@ struct {
|
|||||||
int idx;
|
int idx;
|
||||||
const char *tilelabel;
|
const char *tilelabel;
|
||||||
const char *expectedlabel;
|
const char *expectedlabel;
|
||||||
} altlabels[MAXPCHARS] = {
|
} altlabels[MAXPCHARS + 1] = {
|
||||||
#define PCHAR_TILES
|
#define PCHAR_TILES
|
||||||
#include "defsym.h"
|
#include "defsym.h"
|
||||||
#undef PCHAR_TILES
|
#undef PCHAR_TILES
|
||||||
|
|||||||
Reference in New Issue
Block a user