From 361e6a924a823c94733f44974867e661011fe38d Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sat, 28 May 2022 17:25:29 +0300 Subject: [PATCH] Fix segfault with fire trap on ice and monster triggering it When a monster with innate teleporting stepped on a fire trap on ice, the ice melted and the monster teleported away before falling into the pool. If the monster's new location had a trap, the code tried to access the deleted fire trap. --- src/trap.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/trap.c b/src/trap.c index 0663dbc4c..6f46d6942 100644 --- a/src/trap.c +++ b/src/trap.c @@ -1468,8 +1468,9 @@ trapeffect_fire_trap( seetrap(trap); dofiretrap((struct obj *) 0); } else { + coordxy tx = trap->tx, ty = trap->ty; boolean in_sight = canseemon(mtmp) || (mtmp == u.usteed); - boolean see_it = cansee(mtmp->mx, mtmp->my); + boolean see_it = cansee(tx, ty); boolean trapkilled = FALSE; struct permonst *mptr = mtmp->data; @@ -1527,13 +1528,13 @@ trapeffect_fire_trap( (void) destroy_mitem(mtmp, POTION_CLASS, AD_FIRE); ignite_items(mtmp->minvent); } - if (burn_floor_objects(mtmp->mx, mtmp->my, see_it, FALSE) - && !see_it && distu(mtmp->mx, mtmp->my) <= 3 * 3) + if (burn_floor_objects(tx, ty, see_it, FALSE) + && !see_it && distu(tx, ty) <= 3 * 3) You("smell smoke."); - if (is_ice(mtmp->mx, mtmp->my)) - melt_ice(mtmp->mx, mtmp->my, (char *) 0); - if (see_it && t_at(mtmp->mx, mtmp->my)) - seetrap(trap); + if (is_ice(tx, ty)) + melt_ice(tx, ty, (char *) 0); + if (see_it && t_at(tx, ty)) + seetrap(t_at(tx, ty)); return trapkilled ? Trap_Killed_Mon : mtmp->mtrapped ? Trap_Caught_Mon : Trap_Effect_Finished;