Skip to content

fix: eliminate oob array access in function parameter counting#185

Merged
cs01 merged 1 commit intomainfrom
fix-compiler-oob-access
Mar 10, 2026
Merged

fix: eliminate oob array access in function parameter counting#185
cs01 merged 1 commit intomainfrom
fix-compiler-oob-access

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 10, 2026

Summary

  • The compiler used while (arr[idx]) to count function parameters, which accesses index 0 of an empty array when a function has no parameters. In JavaScript this silently returns undefined, but with runtime bounds checking enabled this becomes a crash.
  • Replaced with direct .length check — simpler and correct for all cases.

What this means for users

Previously, enabling full bounds checking (for string/object arrays) would cause the compiler itself to crash when compiling any code containing parameterless functions. This fix eliminates one of the compiler's own out-of-bounds array accesses, bringing us closer to enabling bounds checking across all array types.

Test plan

  • All 451 compiler tests pass
  • Self-hosting Stage 0 + Stage 1 pass
  • Verified parameterless function compilation works with bounds checking enabled

🤖 Generated with Claude Code

@cs01 cs01 merged commit 2923a04 into main Mar 10, 2026
12 checks passed
@cs01 cs01 deleted the fix-compiler-oob-access branch March 12, 2026 05:34
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