Skip to content

Commit

Permalink
Fix for bug C343-172.
Browse files Browse the repository at this point in the history
The DevTeam describes this bug as:  "Crash could occur when monster uses potion
or food to cure stoning or confusion."  The crash occurs because
mon_consume_unstone calls m_useup (which may free obj) and then uses obj
afterwards.
  • Loading branch information
chasonr committed Feb 1, 2014
1 parent 5509d59 commit 7da438e
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/muse.c
Expand Up @@ -2127,7 +2127,10 @@ struct obj *obj;
boolean by_you;
boolean stoning;
{
int nutrit = (obj->otyp == CORPSE) ? dog_nutrition(mon, obj) : 0;
/* Save otyp and corpsenm for use after m_useup */
short obj_otyp = obj->otyp;
int obj_corpsenm = obj->corpsenm;
int nutrit = (obj_otyp == CORPSE) ? dog_nutrition(mon, obj) : 0;
/* also sets meating */

/* give a "<mon> is slowing down" message and also remove
Expand All @@ -2139,13 +2142,13 @@ boolean stoning;

obj->quan = 1L;
pline("%s %ss %s.", Monnam(mon),
(obj->otyp == POT_ACID) ? "quaff" : "eat",
(obj_otyp == POT_ACID) ? "quaff" : "eat",
distant_name(obj,doname));
obj->quan = save_quan;
} else if (flags.soundok)
You_hear("%s.", (obj->otyp == POT_ACID) ? "drinking" : "chewing");
You_hear("%s.", (obj_otyp == POT_ACID) ? "drinking" : "chewing");
m_useup(mon, obj);
if (((obj->otyp == POT_ACID) || acidic(&mons[obj->corpsenm])) &&
if (((obj_otyp == POT_ACID) || acidic(&mons[obj_corpsenm])) &&
!resists_acid(mon)) {
mon->mhp -= rnd(15);
pline("%s has a very bad case of stomach acid.",
Expand All @@ -2164,7 +2167,7 @@ boolean stoning;
else
pline("%s seems limber!", Monnam(mon));
}
if (obj->otyp == CORPSE && obj->corpsenm == PM_LIZARD && mon->mconf) {
if (obj_otyp == CORPSE && obj_corpsenm == PM_LIZARD && mon->mconf) {
mon->mconf = 0;
if (canseemon(mon))
pline("%s seems steadier now.", Monnam(mon));
Expand Down

0 comments on commit 7da438e

Please sign in to comment.