From: Katie Hockman Date: Fri, 9 Apr 2021 19:50:40 +0000 (-0400) Subject: [dev.fuzz] internal/fuzz: allow float types to be integer literals X-Git-Tag: go1.18beta1~1282^2~69 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8b96efd8a274a65504dc9051e0545379d26f8445;p=gostls13.git [dev.fuzz] internal/fuzz: allow float types to be integer literals Previously, something like `float64(0)` would fail to decode since the 0 value is considered an integer literal, and the float64 parsing code required a float literal. Be more flexible here since an integer can always be converted to a float. Change-Id: Id1c53ef2e8a9748a4f71176b00b453a329af4ade Reviewed-on: https://go-review.googlesource.com/c/go/+/309032 Trust: Katie Hockman Run-TryBot: Katie Hockman TryBot-Result: Go Bot Reviewed-by: Jay Conrod --- diff --git a/src/internal/fuzz/encoding.go b/src/internal/fuzz/encoding.go index c018ef5fe2..c2f7d22b75 100644 --- a/src/internal/fuzz/encoding.go +++ b/src/internal/fuzz/encoding.go @@ -181,14 +181,14 @@ func parseCorpusValue(line []byte) (interface{}, error) { } return parseUint(val, typ) case "float32": - if kind != token.FLOAT { - return nil, fmt.Errorf("float literal required for float32 type") + if kind != token.FLOAT && kind != token.INT { + return nil, fmt.Errorf("float or integer literal required for float32 type") } v, err := strconv.ParseFloat(val, 32) return float32(v), err case "float64": - if kind != token.FLOAT { - return nil, fmt.Errorf("float literal required for float64 type") + if kind != token.FLOAT && kind != token.INT { + return nil, fmt.Errorf("float or integer literal required for float64 type") } return strconv.ParseFloat(val, 64) default: diff --git a/src/internal/fuzz/encoding_test.go b/src/internal/fuzz/encoding_test.go index cbf4999f8d..3cd8d0e2ab 100644 --- a/src/internal/fuzz/encoding_test.go +++ b/src/internal/fuzz/encoding_test.go @@ -72,6 +72,13 @@ string("extra") }, { in: `go test fuzz v1 +float64(0) +float32(0) +`, + ok: true, // will be an integer literal since there is no decimal + }, + { + in: `go test fuzz v1 int(-23) int8(-2) int64(2342425)