fix: Coefficient panic

call Coefficient on uninitialized Decimal will panic
This commit is contained in:
coldWater 2019-06-17 18:13:00 +08:00 committed by GitHub
parent cd690d0c9e
commit 62587fc365
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -657,6 +657,7 @@ func (d Decimal) Exponent() int32 {
// Coefficient returns the coefficient of the decimal. It is scaled by 10^Exponent() // Coefficient returns the coefficient of the decimal. It is scaled by 10^Exponent()
func (d Decimal) Coefficient() *big.Int { func (d Decimal) Coefficient() *big.Int {
d.ensureInitialized()
// we copy the coefficient so that mutating the result does not mutate the // we copy the coefficient so that mutating the result does not mutate the
// Decimal. // Decimal.
return big.NewInt(0).Set(d.value) return big.NewInt(0).Set(d.value)