pgtype
pgtype copied to clipboard
Unsafe type float64 conversion to float32 in AssignTo
trafficstars
Referring to here: https://github.com/jackc/pgtype/blob/12c49ee213fabc092f24b92db6874ed0d319d7b3/ext/shopspring-numeric/decimal.go#L127
case *float32:
f, _ := src.Decimal.Float64()
*v = float32(f)
The value f should perhaps be checked for overflow against float32, and return an overflow error when it occurs?
Maybe... 🤷
shopspring decimal internally uses https://pkg.go.dev/math/big#Rat.Float64 can already overflow the float64 to +Inf. The float64 to float32 does the same thing.