Repository navigation
Size makemaz() DFS stack for the full maze grid - #9
Merged
Merged
Conversation
makemaz() builds the bottom-level maze with an explicit depth-first stack, int stack[200]. Maze cells sit at odd coordinates, 8 rows x 37 columns = 296 cells; each is pushed at most once and stack[0] is unused, so the deepest path needs 8*37+1 entries. Measured over 3000 seeds the depth ranged 90-232, and 6.9% of maze levels ran past index 199, smashing the stack (SIGABRT with the stack protector, silent corruption otherwise). Size the array from the grid bound; keep the original declaration under #if 0. The algorithm is unchanged: with ASLR disabled, 9285/9285 non-overflowing seeds produce byte-identical level files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rflow # Conflicts: # docs/CHANGELOG.md
…rflow # Conflicts: # docs/CHANGELOG.md
neuhaus
pushed a commit
to neuhaus/protoHack
that referenced
this pull request
Nov 15, 2026
Size makemaz() DFS stack for the full maze grid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug: maze levels (the bottom of the dungeon, depth 25–29) crash on about 7% of seeds. Repro:
./mklev lvtest b 30 16→*** stack smashing detected ***(ASan:stack-buffer-overflowatsrc/root/mklev.c:446,stack[++sp]). This happens with signed and unsignedcharalike. It's unrelated to #8.Cause: Kenny Woodland's
makemaz()(the "this is all Kenny's fault" function) is a depth-first maze carver with an explicit stack,int stack[200]. Maze cells sit at odd coordinates: 8 rows (3..17,MAZY) × 37 columns (3..75,MAZX) = 296 cells. Each cell is pushed at most once (it's markedtyp=2as soon as it reaches the top), andstack[0]is unused, so the worst case needs 8·37+1 = 297 entries. Measured depth over 3000 seeds: min 90, median 159, max 232, and 207/3000 (6.9%) went past index 199.Fix:
int stack[8*37+1];, with the bound explained in aModern:comment and the original declaration kept under#if 0.original/is untouched, and the algorithm is unchanged.Verification (Debug builds;
mklev <file> <type> <depth> <seed>):b, depths 25–29 × seeds 1–2000, ASan+UBSan-funsigned-char(simulated aarch64), depths 25/27/29 × 1000setarch -R, since saved structs contain heap pointers)a(depths 3, 15) and above-mazen(24, 28) × 300 seeds, ASanNot fixed here (pre-existing, separate): seed 215 hangs or segfaults on
a/nlevels on the old and new builds alike (it never reachesmakemaz()). Worth its own issue.Brouwer's Hack 1.0.3 (restoHack) isn't affected. It replaced this explicit stack with a recursive
walkfrom().🤖 Generated with Claude Code