From: Pasi Kallinen Date: Mon, 25 May 2015 19:02:59 +0000 (+0300) Subject: Fix squeaky board creation segfault X-Git-Tag: NetHack-3.6.0_RC01~359 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=29ecd78efc31206c763cc5fa5a4e5e6eb5552e38;p=nethack Fix squeaky board creation segfault 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. --- diff --git a/src/trap.c b/src/trap.c index b66d06bcf..ff36cbe8a 100644 --- a/src/trap.c +++ b/src/trap.c @@ -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 */