From 27f6ae340bf030166184e38cfe6198d5e0186d2e Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 25 Apr 2026 13:14:33 -0700 Subject: [PATCH] address issue #1490 - rolling boulder segfault Issue reported by BartekCupial: segfault occurred and was tracked to behavior of a rolling boulder trap. Suggested fix was included, but it assumes that the destination spot is valid so is suspect. A comment pointed out that the path is validated when a rolling boulder trap is created so the segfault should be impossible. I didn't find an explanation but am adding a fix based on the one in the issue report. Closes #1490 --- doc/fixes3-7-0.txt | 1 + src/trap.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index 1f281f47c..aa27902a7 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -1602,6 +1602,7 @@ when starting a new game as a monk, newsym(0,0) was being called (adjabil -> postadjabil -> see_monsters when initializing See_invisible as hero became level 1; seen 'monster' was the hero who hadn't been placed on the map yet) +incorporate a fix to prevent segfault due to rolling boulder trap Fixes to 3.7.0-x General Problems Exposed Via git Repository diff --git a/src/trap.c b/src/trap.c index cc62fdd3e..a97706fe8 100644 --- a/src/trap.c +++ b/src/trap.c @@ -3375,6 +3375,23 @@ launch_obj( while (tmp-- > 0) nh_delay_output(); + /* + * TEMPORARY? github issue #1490 by BartekCupial reports a + * segfault when boulder rolls out of bounds. That should be + * impossible because trap creation validates the path that + * the boulder will traverse. + * + * The suggested fix increments bhitpos, verifies with isok(), + * then undoes the increment if not ok. This is simpler. + */ + if (!isok(gb.bhitpos.x + dx, gb.bhitpos.y + dy)) { + x2 = x, y2 = y; /* use current spot for final boulder placement */ + break; + } + /* + * end TEMPORARY? + */ + x = (gb.bhitpos.x += dx); y = (gb.bhitpos.y += dy);