pull request #1175 - obj->corpsenm fixes
Pull request by mkuoppal: some objects which use the corpsenm field to access the mons[] array can have a corpsenm value of NON_PM (-1) and weren't avoiding array access in those cases. In addition to a fixes entry for it, this makes some revisions to the commited code, handling a few of the cases differently. Closes #1175
This commit is contained in:
11
src/dog.c
11
src/dog.c
@@ -929,17 +929,16 @@ dogfood(struct monst *mon, struct obj *obj)
|
||||
switch (obj->oclass) {
|
||||
case FOOD_CLASS:
|
||||
fx = (obj->otyp == CORPSE || obj->otyp == TIN || obj->otyp == EGG)
|
||||
/* corpsenm might be NON_PM (special tin, unhatachable egg) */
|
||||
? obj->corpsenm
|
||||
: NUMMONS; /* valid mons[mndx] to pacify static analyzer */
|
||||
|
||||
fptr = fx >= LOW_PM ? &mons[fx] : NULL;
|
||||
: NON_PM;
|
||||
/* mons[NUMMONS] is valid; predicate tests against it will fail */
|
||||
fptr = &mons[(fx >= LOW_PM) ? fx : NUMMONS];
|
||||
|
||||
if (obj->otyp == CORPSE && is_rider(fptr))
|
||||
return TABU;
|
||||
if ((obj->otyp == CORPSE || obj->otyp == EGG)
|
||||
/* Medusa's corpse doesn't pass the touch_petrifies() test
|
||||
but does cause petrification if eaten */
|
||||
&& ((fptr && touch_petrifies(fptr)) || obj->corpsenm == PM_MEDUSA)
|
||||
&& flesh_petrifies(fptr) /* c*ckatrice or Medusa */
|
||||
&& !resists_ston(mon))
|
||||
return POISON;
|
||||
if (obj->otyp == LUMP_OF_ROYAL_JELLY
|
||||
|
||||
Reference in New Issue
Block a user