Skip to content

fix: add zero-divisor guard to modulo to prevent srem UB#251

Merged
cs01 merged 1 commit intomainfrom
fix/modulo-zero-check
Mar 11, 2026
Merged

fix: add zero-divisor guard to modulo to prevent srem UB#251
cs01 merged 1 commit intomainfrom
fix/modulo-zero-check

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 11, 2026

Summary

  • Integer modulo (srem i64) with a zero divisor is undefined behavior in LLVM — can cause arbitrary wrong results or crashes
  • Added zero-check guards to all three srem code paths (pure i64, known-integer doubles, dynamic integer detection)
  • Zero divisor now returns 0 (i64 path) or NaN (double paths) instead of triggering UB

Test plan

  • New modulo-zero.ts fixture covering basic modulo, negative operands, and float modulo
  • npm run verify:quick passes (tests + self-hosting)

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cs01 cs01 merged commit d2a66df into main Mar 11, 2026
12 checks passed
@cs01 cs01 deleted the fix/modulo-zero-check branch March 12, 2026 05:35
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