Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apd: prevent (*Decimal).Int64 receiver from escaping to heap #104

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,19 +246,19 @@ func (d *Decimal) SetFloat64(f float64) (*Decimal, error) {
// Int64 returns the int64 representation of x. If x cannot be represented in an int64, an error is returned.
func (d *Decimal) Int64() (int64, error) {
if d.Form != Finite {
return 0, errors.Errorf("%s is not finite", d)
return 0, errors.Errorf("%s is not finite", d.String())
}
integ, frac := new(Decimal), new(Decimal)
d.Modf(integ, frac)
if !frac.IsZero() {
return 0, errors.Errorf("%s: has fractional part", d)
return 0, errors.Errorf("%s: has fractional part", d.String())
}
var ed ErrDecimal
if integ.Cmp(New(math.MaxInt64, 0)) > 0 {
return 0, errors.Errorf("%s: greater than max int64", d)
return 0, errors.Errorf("%s: greater than max int64", d.String())
}
if integ.Cmp(New(math.MinInt64, 0)) < 0 {
return 0, errors.Errorf("%s: less than min int64", d)
return 0, errors.Errorf("%s: less than min int64", d.String())
}
if err := ed.Err(); err != nil {
return 0, err
Expand Down