From 29ecd78efc31206c763cc5fa5a4e5e6eb5552e38 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Mon, 25 May 2015 22:02:59 +0300 Subject: [PATCH] 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. --- src/trap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 */