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:
nhmall
2022-09-06 10:00:07 -04:00
parent 817b4686ce
commit 0086e01967
6 changed files with 93 additions and 84 deletions

View File

@@ -3161,13 +3161,12 @@ static boolean
find_poleable_mon(coord *pos, int min_range, int max_range)
{
struct monst *mtmp;
coord mpos;
coord mpos = { 0, 0 }; /* no candidate location yet */
boolean impaired;
coordxy x, y, lo_x, hi_x, lo_y, hi_y, rt;
int glyph;
impaired = (Confusion || Stunned || Hallucination);
mpos.x = mpos.y = 0; /* no candidate location yet */
rt = isqrt(max_range);
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);

View File

@@ -1075,90 +1075,92 @@ tmp_at(coordxy x, coordxy y)
break;
}
if (!tglyph)
if (!tglyph) {
panic("tmp_at: tglyph not initialized");
} else {
switch (x) {
case DISP_CHANGE:
tglyph->glyph = y;
break;
switch (x) {
case DISP_CHANGE:
tglyph->glyph = y;
break;
case DISP_END:
if (tglyph->style == DISP_BEAM || tglyph->style == DISP_ALL) {
register int i;
case DISP_END:
if (tglyph->style == DISP_BEAM || tglyph->style == DISP_ALL) {
register int i;
/* Erase (reset) from source to end */
for (i = 0; i < tglyph->sidx; i++)
newsym(tglyph->saved[i].x, tglyph->saved[i].y);
} else if (tglyph->style == DISP_TETHER) {
int i;
if (y == BACKTRACK && tglyph->sidx > 1) {
/* backtrack */
for (i = tglyph->sidx - 1; i > 0; i--) {
/* Erase (reset) from source to end */
for (i = 0; i < tglyph->sidx; i++)
newsym(tglyph->saved[i].x, tglyph->saved[i].y);
show_glyph(tglyph->saved[i - 1].x,
tglyph->saved[i - 1].y, tglyph->glyph);
flush_screen(0); /* make sure it shows up */
delay_output();
} else if (tglyph->style == DISP_TETHER) {
int i;
if (y == BACKTRACK && tglyph->sidx > 1) {
/* backtrack */
for (i = tglyph->sidx - 1; i > 0; i--) {
newsym(tglyph->saved[i].x, tglyph->saved[i].y);
show_glyph(tglyph->saved[i - 1].x,
tglyph->saved[i - 1].y, tglyph->glyph);
flush_screen(0); /* make sure it shows up */
delay_output();
}
tglyph->sidx = 1;
}
for (i = 0; i < tglyph->sidx; i++)
newsym(tglyph->saved[i].x, tglyph->saved[i].y);
} else { /* DISP_FLASH or DISP_ALWAYS */
if (tglyph->sidx) /* been called at least once */
newsym(tglyph->saved[0].x, tglyph->saved[0].y);
}
/* tglyph->sidx = 0; -- about to be freed, so not necessary */
tmp = tglyph->prev;
if (tglyph != &tgfirst)
free((genericptr_t) tglyph);
tglyph = tmp;
break;
default: /* do it */
if (!isok(x, y))
break;
if (tglyph->style == DISP_BEAM || tglyph->style == DISP_ALL) {
if (tglyph->style != DISP_ALL && !cansee(x, y))
break;
if (tglyph->sidx >= TMP_AT_MAX_GLYPHS)
break; /* too many locations */
/* save pos for later erasing */
tglyph->saved[tglyph->sidx].x = x;
tglyph->saved[tglyph->sidx].y = y;
tglyph->sidx += 1;
} else if (tglyph->style == DISP_TETHER) {
if (tglyph->sidx >= TMP_AT_MAX_GLYPHS)
break; /* too many locations */
if (tglyph->sidx) {
int px, py;
px = tglyph->saved[tglyph->sidx - 1].x;
py = tglyph->saved[tglyph->sidx - 1].y;
show_glyph(px, py, tether_glyph(px, py));
}
/* save pos for later use or erasure */
tglyph->saved[tglyph->sidx].x = x;
tglyph->saved[tglyph->sidx].y = y;
tglyph->sidx += 1;
} else { /* DISP_FLASH/ALWAYS */
if (tglyph
->sidx) { /* not first call, so reset previous pos */
newsym(tglyph->saved[0].x, tglyph->saved[0].y);
tglyph->sidx = 0; /* display is presently up to date */
}
if (!cansee(x, y) && tglyph->style != DISP_ALWAYS)
break;
tglyph->saved[0].x = x;
tglyph->saved[0].y = y;
tglyph->sidx = 1;
}
for (i = 0; i < tglyph->sidx; i++)
newsym(tglyph->saved[i].x, tglyph->saved[i].y);
} else { /* DISP_FLASH or DISP_ALWAYS */
if (tglyph->sidx) /* been called at least once */
newsym(tglyph->saved[0].x, tglyph->saved[0].y);
}
/* tglyph->sidx = 0; -- about to be freed, so not necessary */
tmp = tglyph->prev;
if (tglyph != &tgfirst)
free((genericptr_t) tglyph);
tglyph = tmp;
break;
default: /* do it */
if (!isok(x, y))
show_glyph(x, y, tglyph->glyph); /* show it */
flush_screen(0); /* make sure it shows up */
break;
if (tglyph->style == DISP_BEAM || tglyph->style == DISP_ALL) {
if (tglyph->style != DISP_ALL && !cansee(x, y))
break;
if (tglyph->sidx >= TMP_AT_MAX_GLYPHS)
break; /* too many locations */
/* save pos for later erasing */
tglyph->saved[tglyph->sidx].x = x;
tglyph->saved[tglyph->sidx].y = y;
tglyph->sidx += 1;
} else if (tglyph->style == DISP_TETHER) {
if (tglyph->sidx >= TMP_AT_MAX_GLYPHS)
break; /* too many locations */
if (tglyph->sidx) {
int px, py;
px = tglyph->saved[tglyph->sidx-1].x;
py = tglyph->saved[tglyph->sidx-1].y;
show_glyph(px, py, tether_glyph(px, py));
}
/* save pos for later use or erasure */
tglyph->saved[tglyph->sidx].x = x;
tglyph->saved[tglyph->sidx].y = y;
tglyph->sidx += 1;
} else { /* DISP_FLASH/ALWAYS */
if (tglyph->sidx) { /* not first call, so reset previous pos */
newsym(tglyph->saved[0].x, tglyph->saved[0].y);
tglyph->sidx = 0; /* display is presently up to date */
}
if (!cansee(x, y) && tglyph->style != DISP_ALWAYS)
break;
tglyph->saved[0].x = x;
tglyph->saved[0].y = y;
tglyph->sidx = 1;
}
show_glyph(x, y, tglyph->glyph); /* show it */
flush_screen(0); /* make sure it shows up */
break;
} /* end case */
} /* end switch */
}
}
/*

View File

@@ -66,10 +66,15 @@ const struct symdef def_warnsyms[WARNCOUNT] = {
* parsing other.txt because some of the useful tile names don't exist
* within NetHack itself.
*/
const struct symdef defsyms[MAXPCHARS] = {
const struct symdef defsyms[MAXPCHARS + 1] = {
#define PCHAR_DRAWING
#include "defsym.h"
#undef PCHAR_DRAWING
{ 0, NULL
#ifdef TEXTCOLOR
, NO_COLOR
#endif
}
};
/* default rogue level symbols */
@@ -130,7 +135,7 @@ def_char_is_furniture(char ch)
int i;
boolean furniture = FALSE;
for (i = 0; i < SIZE(defsyms); ++i) {
for (i = 0; i < MAXPCHARS; ++i) {
if (!furniture) {
if (!strncmp(defsyms[i].explanation, first_furniture, 5))
furniture = TRUE;