Skip to content

Fix/i32 min rem overflow (minor) - #5501

Open
Jayesh-Dev21 wants to merge 1 commit into
boa-dev:mainfrom
Jayesh-Dev21:fix/i32-min-rem-overflow
Open

Fix/i32 min rem overflow (minor)#5501
Jayesh-Dev21 wants to merge 1 commit into
boa-dev:mainfrom
Jayesh-Dev21:fix/i32-min-rem-overflow

Conversation

@Jayesh-Dev21

Copy link
Copy Markdown

This Pull Request fixes/closes #5481.

It changes the following:

Fixes a panic when computing (-2147483648 | 0) % (-1 | 0). The fast-path integer remainder operations (rem and rem_fast) used bare x % y on i32 values, which panics on signed integer overflow when x = i32::MIN and y = -1.
Changes

  • core/engine/src/value/operations.rs: Replaced bare x % y with x.checked_rem(y) in both rem() and rem_fast(). On overflow (None), falls back to f64 arithmetic — the same pattern already used by add, sub, mul, and div in the same file.
  • core/engine/src/value/tests.rs: Added regression test rem_i32_min_by_neg_one asserting the result is -0.0.

Verification

  • (-2147483648 | 0) % (-1 | 0) now returns -0 instead of panicking (matches Node.js behaviour)
image
  • Existing rem_by_zero test still passes
  • Clippy clean (both --all-features and --no-default-features)

@github-actions github-actions Bot added the Waiting On Review Waiting on reviews from the maintainers label Aug 30, 2026
@github-actions github-actions Bot added this to the v0.23 milestone Aug 30, 2026
@github-actions github-actions Bot added the C-Tests Issues and PRs related to the tests. label Aug 30, 2026
@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown

Test262 conformance changes

Test result main count PR count difference
Total 53,578 53,578 0
Passed 51,435 51,435 0
Ignored 1,622 1,622 0
Failed 521 521 0
Panics 0 0 0
Conformance 96.00% 96.00% 0.00%

Tested main commit: 10ef23505ecae734a4984d7839fec99a7ca8482c
Tested PR commit: 8b233c465c87f44f4c49e5eaa36b46e51614877c
Compare commits: 10ef235...8b233c4

@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.43%. Comparing base (6ddc2b4) to head (8b233c4).
⚠️ Report is 1049 commits behind head on main.

Files with missing lines Patch % Lines
core/engine/src/value/operations.rs 62.50% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5501       +/-   ##
===========================================
+ Coverage   47.24%   62.43%   +15.19%     
===========================================
  Files         476      534       +58     
  Lines       46892    59747    +12855     
===========================================
+ Hits        22154    37304    +15150     
+ Misses      24738    22443     -2295     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…ev#5481)

The fast-path integer remainder (`rem` and `rem_fast`) used bare
`x % y` which panics when `x = i32::MIN` and `y = -1` due to
signed integer overflow. Replaced with `checked_rem`, falling
back to `f64` arithmetic on overflow — the same pattern already
used by `add`, `sub`, `mul`, and `div` in the same file.

Closes boa-dev#5481
@Jayesh-Dev21
Jayesh-Dev21 force-pushed the fix/i32-min-rem-overflow branch from e6e00dd to 8b233c4 Compare August 31, 2026 15:20
@nekevss

nekevss commented Sep 1, 2026

Copy link
Copy Markdown
Member

Feel free to mark this as ready for review whenever you're ready for a maintainer to take a look

@Jayesh-Dev21
Jayesh-Dev21 marked this pull request as ready for review September 1, 2026 13:26
@Jayesh-Dev21
Jayesh-Dev21 requested a review from a team as a code owner September 1, 2026 13:26
Copilot AI lite review requested due to automatic review settings September 1, 2026 13:26
@Jayesh-Dev21

Copy link
Copy Markdown
Author

@nekevss Marked this Pr as ready for review. Let me know if there's anything you'd like me to change.
Thanks!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new rem_i32_min_by_neg_one test uses assert_eq which treats +0 and -0 as equal, so it doesn’t actually validate the negative-zero behavior.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Fixes an i32 signed-overflow panic in the % fast paths by switching to checked remainder and falling back to f64 arithmetic on overflow, aligning behavior with JavaScript (e.g., producing -0 instead of panicking).

Changes:

  • Replace x % y with x.checked_rem(y) in rem() and rem_fast(), with f64 fallback on overflow.
  • Add regression tests covering i32::MIN % -1 behavior for both the interpreter path and rem_fast().
File summaries
File Description
core/engine/src/value/operations.rs Prevents % overflow panic for i32::MIN % -1 by using checked_rem with f64 fallback and correct -0 sign handling.
core/engine/src/value/tests.rs Adds regression tests for i32::MIN % -1, including a rem_fast() sign-of-zero assertion.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +300 to +303
#[test]
fn rem_i32_min_by_neg_one() {
run_test_actions([TestAction::assert_eq("(-2147483648 | 0) % (-1 | 0)", -0.0)]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Tests Issues and PRs related to the tests. Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic: i32::MIN % -1 remainder overflow

3 participants