Skip to content

Build with -fsigned-char to fix mklev crash on ARM64 - #8

Merged
Critlist merged 2 commits into
mainfrom
fix/signed-char-arm64
Oct 16, 2026
Merged

Critlist merged 2 commits into
mainfrom
fix/signed-char-arm64

Conversation

@Critlist

Copy link
Copy Markdown
Owner

Bug: on ABIs where plain char is unsigned (Linux aarch64, e.g. Raspberry Pi, Asahi, ARM servers), mklev crashes on every normal level. macOS on Apple silicon is unaffected, because Apple's ABI keeps char signed, which is why macOS CI passes.

Cause: Jay's struct mkroom { char lx,hx,ly,hy; } uses croom->hx = -1 (src/root/mklev.c:132, "the only goto in hack") as the end-of-rooms sentinel. Unsigned, -1 becomes 255, so for(croom=room;croom->hx>0;croom++) (:164) runs past the last room, and somex() computes rand() % 0 (SIGFPE) or walks off room[] (SIGSEGV). It's the same bug class as restoHack #15.

Fix: add_compile_options(-fsigned-char), restoring the PDP-11's signed char for all of Jay's plain-char assumptions (also e.g. mhp). No source changes; original/ untouched.

Verification (x86 with -DCMAKE_C_FLAGS=-funsigned-char to simulate aarch64; not tested on real ARM hardware):

before after
mklev normal levels 0/5 seeds (SIGFPE ×4, SIGSEGV ×1) 50/50 (gcc and clang)
game start — reaches level 1

Not fixed here (pre-existing, separate): makemaz() overflows int stack[200] on some seeds (e.g. ./mklev x b 30 16 → stack smashing detected), on both signed and unsigned builds.

🤖 Generated with Claude Code

Jay's mklev marks the end of the room list with croom->hx = -1 in a
plain-char field. On ABIs where char is unsigned (Linux aarch64), -1 is
255, so `for(croom=room; croom->hx>0; croom++)` runs past the last room
and somex() computes rand() % 0 (SIGFPE) or walks off room[] (SIGSEGV).

Simulated with -funsigned-char on x86: mklev crashed on 5/5 seeds;
with this change, 50/50 normal levels pass under gcc and clang and the
game starts. The flag restores the PDP-11's signed char for every
plain-char assumption without touching original or restored source.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Critlist
Critlist merged commit 3cabc96 into main Oct 16, 2026
5 checks passed
neuhaus pushed a commit to neuhaus/protoHack that referenced this pull request Nov 15, 2026
Build with -fsigned-char to fix mklev crash on ARM64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant