From: nhmall Date: Sat, 22 Sep 2018 12:58:38 +0000 (-0400) Subject: avoid illegal array indexes now that the enum treads beyond BL_FLUSH X-Git-Tag: NetHack-3.6.2_Released~194^2~26 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0a52543076ea3f7d7127240e91067c96a03740c1;p=nethack avoid illegal array indexes now that the enum treads beyond BL_FLUSH --- diff --git a/src/windows.c b/src/windows.c index 96d9a218d..db0d53104 100644 --- a/src/windows.c +++ b/src/windows.c @@ -930,7 +930,7 @@ unsigned long *colormasks UNUSED; is buffered so final BL_FLUSH is needed to produce output) */ windowprocs.wincap2 |= WC2_FLUSH_STATUS; - if (idx != BL_FLUSH) { + if (idx >= 0) { if (!status_activefields[idx]) return; switch (idx) { @@ -972,11 +972,15 @@ unsigned long *colormasks UNUSED; break; } return; /* processed one field other than BL_FLUSH */ - } /* (idx != BL_FLUSH) */ + } /* (idx >= 0, thus not BL_FLUSH, BL_RESET, BL_CHARACTERISTICS) */ /* We've received BL_FLUSH; time to output the gathered data */ nb = newbot1; *nb = '\0'; + /* BL_FLUSH is the only pseudo-index value we need to check for + in the loop below because it is the only entry used to pad the + end of the fieldorder array. We could stop on any + negative (illegal) index, but this should be fine */ for (i = 0; (idx1 = fieldorder[0][i]) != BL_FLUSH; ++i) { if (status_activefields[idx1]) Strcpy(nb = eos(nb), status_vals[idx1]);