]> granicus.if.org Git - nethack/commitdiff
Fix squeaky board creation segfault
authorPasi Kallinen <paxed@alt.org>
Mon, 25 May 2015 19:02:59 +0000 (22:02 +0300)
committerPasi Kallinen <paxed@alt.org>
Mon, 25 May 2015 19:03:04 +0000 (22:03 +0300)
If a trap is created on top of another trap, maketrap reuses
the trap struct in place, instead of deleting and recreating it.

If a squeaky trap was created on top of another trap, maketrap
first set the trap type to squeaky board, and then tried to
look through all squeaky boards on the level, to determine
what note the new trap should play. Unfortunately, the union
with the trap note most likely contained a rolling boulder
coordinate or something else outside the 12 note range, so
then the tavail-array lookup would cause a segfault.

src/trap.c

index b66d06bcfa74db6d9f04ee52eba71ef85f1984e5..ff36cbe8a47f492bc941533482a56b973ce79126 100644 (file)
@@ -339,7 +339,7 @@ register int x, y, typ;
         for (k = 0; k < 12; ++k)
             tavail[k] = 0;
         for (t = ftrap; t; t = t->ntrap)
-            if (t->ttyp == SQKY_BOARD)
+            if (t->ttyp == SQKY_BOARD && t != ttmp)
                 tavail[t->tnote] = 1;
 
         /* Now populate tpick with the available indexes */