fix(build): a source with a zero byte is refused by its place, with what to do, before its compiler runs #2150

Merged
HumanBean merged 2 commits from HumanBean/Longshot:zero-byte-source into main 2026-11-21 23:00:31 +00:00
Owner

Summary

A player's nightly 695 build (Windows, launcher 1.2.0) stopped in Compile with only clang's
code_009.split.c:130717:78: error: extraneous ')' before ';'. The line in the log shows why:

recomp_stp32_sp(c,<U+0000>_b+_o),x8_,c->x[9]);

The lifted code_009.c (26 MB) held a zero byte where the ( of (_b+_o) belongs. Nothing in the lift, the giant
splitter or the register locals writes one, so the drive or the memory changed the file after it was written. The
player got a compiler error that looked like a Longshot bug, with nothing saying what to do.

compile_one (nx2/build.py) now reads each source it is about to compile and, if it finds a zero byte, refuses it
before the compiler runs, as one line the launcher shows:

<path>:<line>:<column>: error: this file has a zero byte, which the build never writes: the drive or the PC's memory changed
it after it was written. Build again: the file is made again. If this keeps happening, check the drive for errors and
test the memory

make_game.forget_failed_build already forgets the lift when a code_ file fails, so "Build again" writes the file
again: unchanged here.

Read first: the check at the top of compile_one's compile path, nx2/build.py. It lives inside compile_one rather than in a helper, so the tests that cut compile_one out with ast (test_compiler_failure, test_compile_retry_jobs, test_compile_stops_on_exception, test_mem_gate_leases, test_third_party_objects) still run it unchanged.

Testing

Tested: tests/test_compile_zero_byte.py runs nx2/build.py's own compile_one, cut out with ast, with a stand-in
compiler (no game, no native compiler): a source with a zero byte fails with the error at its line and column, the
compiler never runs, and no object, stamp or cache entry is left; a whole source compiles as before. It is committed
before the fix, so on main the first case fails (the damaged source "compiles"). No tests were run on this PC (the
person I work for runs none here); CI runs them. Not run in the game: the change is in the build, not in anything the
game runs, and a damaged lifted file can't be made in a real build without hand-editing generated output.

Still to test:

  • Windows, a launcher build: a normal build from this PR compiles and links as before (by hand, or any nightly after
    merge)

Measurements

Nothing to measure: the game's code is unchanged, and the build only reads each source it compiles once more (bytes.find over at most ~26 MB, a few milliseconds, against a compile of seconds to minutes), for files not already cached.

Risks

A source holding a zero byte on purpose would now be refused: none in host/, gpu/, third_party/ or nx2/
(grep -rlP '\x00' over their C and C++ files finds none), and the lift never writes one. A revert is enough. Players
notice nothing unless a file is damaged, and then they get a clear message instead of a compiler error.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says. (not run: the change is in the build, not the game; opened with --force at the request of the person I work for; the test runs in CI, not on this PC)
  • mise run test passes (any failure that also fails on main is named). (CI: not run on this PC)
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A check under tests/ that reads changed source is updated, not weakened. (none needed: the check is inside compile_one, so the tests that cut it out need nothing new; to be confirmed by CI)
  • A fix: a game-free test that fails on main and passes here. (written to; to be confirmed by CI on the test-only commit and the head)
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary A player's nightly 695 build (Windows, launcher 1.2.0) stopped in Compile with only clang's `code_009.split.c:130717:78: error: extraneous ')' before ';'`. The line in the log shows why: ``` recomp_stp32_sp(c,<U+0000>_b+_o),x8_,c->x[9]); ``` The lifted `code_009.c` (26 MB) held a zero byte where the `(` of `(_b+_o)` belongs. Nothing in the lift, the giant splitter or the register locals writes one, so the drive or the memory changed the file after it was written. The player got a compiler error that looked like a Longshot bug, with nothing saying what to do. `compile_one` (`nx2/build.py`) now reads each source it is about to compile and, if it finds a zero byte, refuses it before the compiler runs, as one line the launcher shows: ``` <path>:<line>:<column>: error: this file has a zero byte, which the build never writes: the drive or the PC's memory changed it after it was written. Build again: the file is made again. If this keeps happening, check the drive for errors and test the memory ``` `make_game.forget_failed_build` already forgets the lift when a `code_` file fails, so "Build again" writes the file again: unchanged here. Read first: the check at the top of `compile_one`'s compile path, `nx2/build.py`. It lives inside `compile_one` rather than in a helper, so the tests that cut `compile_one` out with `ast` (`test_compiler_failure`, `test_compile_retry_jobs`, `test_compile_stops_on_exception`, `test_mem_gate_leases`, `test_third_party_objects`) still run it unchanged. ## Testing **Tested:** `tests/test_compile_zero_byte.py` runs `nx2/build.py`'s own `compile_one`, cut out with `ast`, with a stand-in compiler (no game, no native compiler): a source with a zero byte fails with the error at its line and column, the compiler never runs, and no object, stamp or cache entry is left; a whole source compiles as before. It is committed before the fix, so on `main` the first case fails (the damaged source "compiles"). No tests were run on this PC (the person I work for runs none here); CI runs them. Not run in the game: the change is in the build, not in anything the game runs, and a damaged lifted file can't be made in a real build without hand-editing generated output. **Still to test:** - Windows, a launcher build: a normal build from this PR compiles and links as before (by hand, or any nightly after merge) ## Measurements Nothing to measure: the game's code is unchanged, and the build only reads each source it compiles once more (`bytes.find` over at most ~26 MB, a few milliseconds, against a compile of seconds to minutes), for files not already cached. ## Risks A source holding a zero byte on purpose would now be refused: none in `host/`, `gpu/`, `third_party/` or `nx2/` (`grep -rlP '\x00'` over their C and C++ files finds none), and the lift never writes one. A revert is enough. Players notice nothing unless a file is damaged, and then they get a clear message instead of a compiler error. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [ ] Tested on my own PC, in the game for a change the game runs, as Testing says. (not run: the change is in the build, not the game; opened with --force at the request of the person I work for; the test runs in CI, not on this PC) - [ ] `mise run test` passes (any failure that also fails on `main` is named). (CI: not run on this PC) - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [ ] A check under `tests/` that reads changed source is updated, not weakened. (none needed: the check is inside `compile_one`, so the tests that cut it out need nothing new; to be confirmed by CI) - [ ] A fix: a game-free test that fails on `main` and passes here. (written to; to be confirmed by CI on the test-only commit and the head) - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(build): a source with a zero byte is refused by its line and column, with what to do, before its compiler runs
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 9s
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 14s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 15s
CI / Workflow lint (actionlint) (pull_request) Successful in 15s
Third-party parts / As their notes say (pull_request) Successful in 17s
CI / Website build and checks (pull_request) Failing after 26s
61097efd74
A player's nightly 695 build stopped on clang's "extraneous ')' before ';'" in code_009.c: the
lifted file held a zero byte where a "(" belonged. Nothing in the translation writes one; the
drive or the memory changed it after it was written. compile_one now finds it first and says so
in the one "error:" line the launcher shows, and make_game still forgets the lift, so the next
build writes the file again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member

Possibly related, for context:

  • issue #1508 Idea: Verify .nup integrity before building — Related: proposes detecting corrupted build input and reporting it clearly.
Possibly related, for context: - issue #1508 Idea: Verify .nup integrity before building — Related: proposes detecting corrupted build input and reporting it clearly.
HumanBean force-pushed zero-byte-source from 61097efd74
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 9s
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 14s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 15s
CI / Workflow lint (actionlint) (pull_request) Successful in 15s
Third-party parts / As their notes say (pull_request) Successful in 17s
CI / Website build and checks (pull_request) Failing after 26s
to 47d18c816a
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 8s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 12s
CI / Workflow lint (actionlint) (pull_request) Successful in 13s
Third-party parts / As their notes say (pull_request) Successful in 13s
CI / Website build and checks (pull_request) Failing after 21s
PR description / Description follows the template (pull_request_target) Failing after 5s
2026-11-21 22:56:02 +00:00
Compare
Author
Owner

The check moved inside compile_one, so the tests that cut compile_one out with ast run it unchanged; Measurements is one line.

The check moved inside compile_one, so the tests that cut compile_one out with ast run it unchanged; Measurements is one line.
HumanBean changed title from WIP: fix(build): a source with a zero byte is refused by its place, with what to do, before its compiler runs to fix(build): a source with a zero byte is refused by its place, with what to do, before its compiler runs 2026-11-21 23:00:18 +00:00
HumanBean deleted branch zero-byte-source 2026-11-21 23:00:32 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2150
No description provided.