src/mon: Avoid addressing with invalid corpsenm in mstoning
corpsenm can be -1 (for EGGs and TINs) so touch_petrifies using this as index would point to bad entry. Fix this by making mstoning as helper function and bailing out early if corpsenm <= LOW_PM (while keeping MEDUSA as is)
This commit is contained in:
19
src/mon.c
19
src/mon.c
@@ -11,6 +11,7 @@ static void sanity_check_single_mon(struct monst *, boolean, const char *);
|
||||
static struct obj *make_corpse(struct monst *, unsigned);
|
||||
static int minliquid_core(struct monst *);
|
||||
static void m_calcdistress(struct monst *);
|
||||
static boolean mstoning(const struct obj *obj);
|
||||
static boolean monlineu(struct monst *, int, int);
|
||||
static long mm_2way_aggression(struct monst *, struct monst *);
|
||||
static long mm_aggression(struct monst *, struct monst *);
|
||||
@@ -1156,9 +1157,19 @@ meatbox(struct monst *mon, struct obj *otmp)
|
||||
}
|
||||
}
|
||||
|
||||
#define mstoning(obj) \
|
||||
(ofood(obj) && (touch_petrifies(&mons[(obj)->corpsenm]) \
|
||||
|| (obj)->corpsenm == PM_MEDUSA))
|
||||
static boolean
|
||||
mstoning(const struct obj *obj)
|
||||
{
|
||||
const int nm = obj->corpsenm;
|
||||
|
||||
if (nm < LOW_PM)
|
||||
return FALSE;
|
||||
|
||||
if (nm == PM_MEDUSA)
|
||||
return TRUE;
|
||||
|
||||
return ofood(obj) && touch_petrifies(&mons[nm]);
|
||||
}
|
||||
|
||||
/* monster consumes an object.
|
||||
|
||||
@@ -1418,8 +1429,6 @@ meatobj(struct monst* mtmp) /* for gelatinous cubes */
|
||||
return (count > 0 || ecount > 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
#undef mstoning
|
||||
|
||||
/* Monster eats a corpse off the ground.
|
||||
* Return value is 0 = nothing eaten, 1 = ate a corpse, 2 = died */
|
||||
int
|
||||
|
||||
Reference in New Issue
Block a user