]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.fuzz] internal/fuzz: allow float types to be integer literals
authorKatie Hockman <katie@golang.org>
Fri, 9 Apr 2021 19:50:40 +0000 (15:50 -0400)
committerKatie Hockman <katie@golang.org>
Mon, 12 Apr 2021 18:51:16 +0000 (18:51 +0000)
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 <katie@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/internal/fuzz/encoding.go
src/internal/fuzz/encoding_test.go

index c018ef5fe230e5bb9f16e1148b2a4a6ad9c2095b..c2f7d22b752c3622d12fe4505cf9a63e87b855f5 100644 (file)
@@ -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:
index cbf4999f8db9ea2d8e2384f3319d670d9cff2572..3cd8d0e2ab202c1cab4131344a1da0e0435b806e 100644 (file)
@@ -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)