Skip to content

fix: reject overflowing division precision - #472

Merged
mwoss merged 2 commits into
shopspring:masterfrom
yuefdev:fix/division-precision-overflow
Oct 18, 2026
Merged

mwoss merged 2 commits into
shopspring:masterfrom
yuefdev:fix/division-precision-overflow

Conversation

@yuefdev

@yuefdev yuefdev commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Reject math.MinInt32 before negating division precision. Negating this value as an int32 wraps back to itself, so the existing exponent check can miss the overflow and return an incorrect non-zero quotient.

The regression uses New(1, math.MinInt32) divided by one, without constructing a huge number. Both QuoRem and DivRound fail the regression before the fix. The adjacent valid precision bounds are checked too.

Focused division tests, go vet ./... and formatting pass.

yuefdev and others added 2 commits October 18, 2026 17:30
Signed-off-by: Yusuf Efe <120668197+yuefdev@users.noreply.github.com>
Move the test next to the other overflow panic tests and use didPanic.
@mwoss

mwoss commented Oct 18, 2026

Copy link
Copy Markdown
Member

Thanks, good catch! I pushed a small cleanup on top: the MinInt32 check is now part of the existing overflow check, so there's one panic site. The test moved into TestDecimal_Overflow next to the other overflow panics and uses didPanic. I kept the MinInt32+1 boundary case and dropped the doc line, since the other overflow panics aren't documented either. Same behavior, just less code.

@mwoss
mwoss merged commit 4ce352f into shopspring:master Oct 18, 2026
7 checks passed
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.

2 participants