static analyzer bit in uhitm.c

src/uhitm.c(1172): warning: Reading invalid data from 'mons'.

Analyzer wasn't happy with the index into mons[] array only
being validated by '!= -1'.

Update the check for the index to include the full array
index range, including ensuring that it is also '< NUMMONS'.
This commit is contained in:
nhmall
2023-12-22 16:28:43 -05:00
parent 51bf9dd76d
commit fcc91cec94

View File

@@ -1169,10 +1169,11 @@ hmon_hitmon_misc_obj(
return;
/*return (boolean) (!DEADMONSTER(mon));*/
} else { /* ordinary egg(s) */
const char *eggp = (obj->corpsenm != NON_PM
&& obj->known)
? the(mons[obj->corpsenm].pmnames[NEUTRAL])
: (cnt > 1L) ? "some" : "an";
enum monnums mnum = obj->corpsenm;
const char *eggp =
(mnum >= LOW_PM && mnum < NUMMONS && obj->known)
? the(mons[mnum].pmnames[NEUTRAL])
: (cnt > 1L) ? "some" : "an";
You("hit %s with %s egg%s.", mon_nam(mon), eggp,
plur(cnt));