github pull request #406 - polyfodder() macro

Some eggs and tins could cause an out of bounds index into the
mons[] array.  Post-3.6 bug: the faulty part of the test is only
relevant for 3.7 genetic engineer monster.  Earlier versions just
called pm_to_cham() which does it's own index validation.

Fixes #406
This commit is contained in:
PatR
2020-11-05 16:03:05 -08:00
parent e4106bb161
commit 096511b509
2 changed files with 10 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.7 obj.h $NHDT-Date: 1604442292 2020/11/03 22:24:52 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.78 $ */
/* NetHack 3.7 obj.h $NHDT-Date: 1604620981 2020/11/06 00:03:01 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.79 $ */
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/*-Copyright (c) Michael Allison, 2006. */
/* NetHack may be freely redistributed. See license for details. */
@@ -247,13 +247,16 @@ struct obj {
#define stale_egg(egg) \
((g.monstermoves - (egg)->age) > (2 * MAX_EGG_HATCH_TIME))
#define ofood(o) ((o)->otyp == CORPSE || (o)->otyp == EGG || (o)->otyp == TIN)
/* note: sometimes eggs and tins have special corpsenm values that
shouldn't be used as an index into mons[] */
#define polyfodder(obj) \
(ofood(obj) && (pm_to_cham((obj)->corpsenm) != NON_PM \
(ofood(obj) && (obj)->corpsenm >= LOW_PM \
&& (pm_to_cham((obj)->corpsenm) != NON_PM \
|| dmgtype(&mons[(obj)->corpsenm], AD_POLY)))
#define mlevelgain(obj) (ofood(obj) && (obj)->corpsenm == PM_WRAITH)
#define mhealup(obj) (ofood(obj) && (obj)->corpsenm == PM_NURSE)
#define Is_pudding(o) \
(o->otyp == GLOB_OF_GRAY_OOZE || o->otyp == GLOB_OF_BROWN_PUDDING \
#define Is_pudding(o) \
(o->otyp == GLOB_OF_GRAY_OOZE || o->otyp == GLOB_OF_BROWN_PUDDING \
|| o->otyp == GLOB_OF_GREEN_SLIME || o->otyp == GLOB_OF_BLACK_PUDDING)
/* Containers */