]> granicus.if.org Git - nethack/commitdiff
Fix segfault with fire trap on ice and monster triggering it
authorPasi Kallinen <paxed@alt.org>
Sat, 28 May 2022 14:25:29 +0000 (17:25 +0300)
committerPasi Kallinen <paxed@alt.org>
Tue, 5 Jul 2022 07:51:28 +0000 (10:51 +0300)
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

index 0663dbc4c39b046c8ec9581260a8c76bc829ab29..6f46d6942c78def66e7281fee84253481abf215b 100644 (file)
@@ -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;