diff --git a/src/zap.c b/src/zap.c index f649436a7..fa3795560 100644 --- a/src/zap.c +++ b/src/zap.c @@ -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; diff --git a/sys/share/uudecode.c b/sys/share/uudecode.c index f3a2cb764..223b94031 100644 --- a/sys/share/uudecode.c +++ b/sys/share/uudecode.c @@ -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) diff --git a/util/makedefs.c b/util/makedefs.c index 1147921f0..6dfb582f2 100644 --- a/util/makedefs.c +++ b/util/makedefs.c @@ -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; diff --git a/win/share/tilemap.c b/win/share/tilemap.c index 6fd2a2803..ec26f513b 100644 --- a/win/share/tilemap.c +++ b/win/share/tilemap.c @@ -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" */ diff --git a/win/share/tiletext.c b/win/share/tiletext.c index b2e71caf6..ac9a8afd7 100644 --- a/win/share/tiletext.c +++ b/win/share/tiletext.c @@ -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); } } }