fix(math): check for negative precision (#14922)
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
parent
fd7bbd7e8d
commit
88909d6f2b
@ -69,6 +69,10 @@ func LegacySmallestDec() LegacyDec { return LegacyDec{new(big.Int).Set(oneInt)}
|
||||
|
||||
// calculate the precision multiplier
|
||||
func calcPrecisionMultiplier(prec int64) *big.Int {
|
||||
if prec < 0 {
|
||||
panic(fmt.Sprintf("negative precision %v", prec))
|
||||
}
|
||||
|
||||
if prec > LegacyPrecision {
|
||||
panic(fmt.Sprintf("too much precision, maximum %v, provided %v", LegacyPrecision, prec))
|
||||
}
|
||||
@ -79,6 +83,10 @@ func calcPrecisionMultiplier(prec int64) *big.Int {
|
||||
|
||||
// get the precision multiplier, do not mutate result
|
||||
func precisionMultiplier(prec int64) *big.Int {
|
||||
if prec < 0 {
|
||||
panic(fmt.Sprintf("negative precision %v", prec))
|
||||
}
|
||||
|
||||
if prec > LegacyPrecision {
|
||||
panic(fmt.Sprintf("too much precision, maximum %v, provided %v", LegacyPrecision, prec))
|
||||
}
|
||||
|
||||
@ -714,3 +714,9 @@ func TestFormatDecNonDigits(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNegativePrecisionPanic(t *testing.T) {
|
||||
require.Panics(t, func() {
|
||||
math.LegacyNewDecWithPrec(10, -1)
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user