some static analyzer items

This commit is contained in:
nhmall
2024-10-04 12:34:09 -04:00
parent 35220e44cb
commit 5af723669e
5 changed files with 29 additions and 12 deletions

View File

@@ -5936,8 +5936,8 @@ destroy_items(
i = (elig_stacks < limit) ? elig_stacks : rn2(elig_stacks);
/* do this afterwards to avoid not filling items_to_destroy[0] */
elig_stacks++;
if (i >= limit) {
/* random index was too high */
if (i < 0 || i >= limit) {
/* random index was too high; mollify analyzer by including < 0 */
continue;
}
items_to_destroy[i].oid = obj->o_id;

View File

@@ -158,6 +158,7 @@ main(int argc, char **argv)
strcpy(dest, dnbuf);
}
#endif /* !MSDOS && !VMS && !WIN32 && !__APPLE__ */
dest[sizeof dest - 1] = '\0';
/* create output file */
#if defined(MSDOS) || defined(WIN32)

View File

@@ -482,7 +482,7 @@ getfp(const char *template, const char *tag, const char *mode, int flg)
err = tmpfile_s(&rv);
#if defined(MSDOS) || defined(WIN32)
if (!err && (!strcmp(mode, WRTMODE) || !strcmp(mode, RDTMODE))) {
_setmode(fileno(rv), O_TEXT);
(void) _setmode(fileno(rv), O_TEXT);
}
#endif
} else
@@ -1321,6 +1321,10 @@ do_data(void)
/* reprocess the scratch file; 1st format an error msg, just in case */
line = malloc(BUFSZ + MAXFNAMELEN);
if (!line) {
fprintf(stderr, "makedefs malloc() failure\n");
exit(EXIT_FAILURE);
}
Sprintf(line, "rewind of \"%s\"", tempfile);
if (rewind(tfp) != 0)
goto dead_data;

View File

@@ -1499,14 +1499,19 @@ add_tileref(
char buf[BUFSZ];
if (!tilelist[n]) {
tilelist[n] = malloc(sizeof temp);
tilelist[n]->tilenum = n;
tilelist[n]->src = src;
tilelist[n]->file_entry = entrynum;
/* leave room for trailing "...nnnn" */
Snprintf(tilelist[n]->tilenam, sizeof tilelist[n]->tilenam - 7,
"%s%s", prefix, nam);
tilelist[n]->references[0] = '\0';
if ((tilelist[n] = malloc(sizeof temp)) != 0) {
tilelist[n]->tilenum = n;
tilelist[n]->src = src;
tilelist[n]->file_entry = entrynum;
/* leave room for trailing "...nnnn" */
Snprintf(tilelist[n]->tilenam, sizeof tilelist[n]->tilenam - 7,
"%s%s", prefix, nam);
tilelist[n]->references[0] = '\0';
} else {
Fprintf(stderr, "tilemap malloc failure %zu bytes\n",
sizeof temp);
exit(EXIT_FAILURE);
}
}
Snprintf(temp.references,
sizeof temp.references - 7, /* room for "...nnnn" */

View File

@@ -199,6 +199,9 @@ read_txttile(FILE *txtfile, pixel (*pixels)[TILE_X])
if (reslt <= 0)
goto done;
ttype[sizeof ttype - 1] = '\0';
buf[sizeof buf - 1] = '\0';
if (tile_set == MONSTER_SET && gend[0] == 'f')
gidx = 1;
@@ -260,10 +263,14 @@ read_txttile(FILE *txtfile, pixel (*pixels)[TILE_X])
}
if (k == -1) {
Fprintf(stderr, "color %c not in colormap!\n", inbuf[i]);
} else {
} else if (k >= 0 && k < MAXCOLORMAPSIZE) {
pixels[j][i].r = ColorMap[CM_RED][k];
pixels[j][i].g = ColorMap[CM_GREEN][k];
pixels[j][i].b = ColorMap[CM_BLUE][k];
} else {
Fprintf(stderr,
"%d exceeds array boundary for ColorMap[][%d]!\n",
k, MAXCOLORMAPSIZE);
}
}
}