Skip to content

Fix panic in format64_to_fixed when rounding carries past all integer digits#56

Open
Ansh-699 wants to merge 1 commit intoboa-dev:mainfrom
Ansh-699:fix/toFixed-rounding-panic
Open

Fix panic in format64_to_fixed when rounding carries past all integer digits#56
Ansh-699 wants to merge 1 commit intoboa-dev:mainfrom
Ansh-699:fix/toFixed-rounding-panic

Conversation

@Ansh-699
Copy link

Summary

Fixes #55.

format64_to_fixed panics in debug builds when rounding causes a carry that propagates through all integer digits (e.g. 9.5 with fraction_digits=0).

Root Cause

The rounding loop calls result.get(round_index) before checking round_index == -1, causing an out-of-bounds read when every integer digit is 9 and the carry reaches index -1.

Fix

Move the round_index == -1 boundary check before the result.get() call, and split it from the c == b'-' check into its own branch.

Tests

Added rounding_carry_past_all_digits and rounding_carry_negative tests. All 70 tests pass.

… digits Check round_index == -1 before calling result.get(round_index) in the rounding loop, preventing an out-of-bounds read when the carry propagates through all integer digits (e.g. 9.5 with fraction_digits=0 should produce "10" but instead panics in debug builds). Fixes boa-dev#55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant