From fcc91cec94d217974113efaf6192b9f115f11018 Mon Sep 17 00:00:00 2001 From: nhmall Date: Fri, 22 Dec 2023 16:28:43 -0500 Subject: [PATCH] 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'. --- src/uhitm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/uhitm.c b/src/uhitm.c index d8e0ca3ee..89f38b7ae 100644 --- a/src/uhitm.c +++ b/src/uhitm.c @@ -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));