aboutsummaryrefslogtreecommitdiff
path: root/src/internal/fuzz/encoding.go
diff options
context:
space:
mode:
authorKatie Hockman <katie@golang.org>2021-09-10 11:05:29 -0400
committerKatie Hockman <katie@golang.org>2021-09-10 19:27:54 +0000
commitd106089fa6aa69cc1b547c68ca19d84f28062c71 (patch)
treebc6c1328910788843d8adaff1d9ce3c974e5a1b1 /src/internal/fuzz/encoding.go
parent363f2f3df99f3edd15609cc6bea2a2c6f423ce2c (diff)
downloadgo-d106089fa6aa69cc1b547c68ca19d84f28062c71.tar.xz
[dev.fuzz] internal/fuzz: write a newline to the end of a corpus file
If someone manually adds/alters a corpus file to add extra spacing or remove the final newline, the file can still be decoded. However, this change ensures that the fuzzing engine correctly writes the final newline. Fixes golang/go#48130 Change-Id: Ib5556d4a6e4e0bfd9bc2edab357b7c25bedfd176 Reviewed-on: https://go-review.googlesource.com/c/go/+/349055 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>
Diffstat (limited to 'src/internal/fuzz/encoding.go')
-rw-r--r--src/internal/fuzz/encoding.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/internal/fuzz/encoding.go b/src/internal/fuzz/encoding.go
index c2f7d22b75..d3f24c3e6c 100644
--- a/src/internal/fuzz/encoding.go
+++ b/src/internal/fuzz/encoding.go
@@ -22,21 +22,21 @@ func marshalCorpusFile(vals ...interface{}) []byte {
if len(vals) == 0 {
panic("must have at least one value to marshal")
}
- b := bytes.NewBuffer([]byte(encVersion1))
+ b := bytes.NewBuffer([]byte(encVersion1 + "\n"))
// TODO(katiehockman): keep uint8 and int32 encoding where applicable,
// instead of changing to byte and rune respectively.
for _, val := range vals {
switch t := val.(type) {
case int, int8, int16, int64, uint, uint16, uint32, uint64, float32, float64, bool:
- fmt.Fprintf(b, "\n%T(%v)", t, t)
+ fmt.Fprintf(b, "%T(%v)\n", t, t)
case string:
- fmt.Fprintf(b, "\nstring(%q)", t)
+ fmt.Fprintf(b, "string(%q)\n", t)
case rune: // int32
- fmt.Fprintf(b, "\nrune(%q)", t)
+ fmt.Fprintf(b, "rune(%q)\n", t)
case byte: // uint8
- fmt.Fprintf(b, "\nbyte(%q)", t)
+ fmt.Fprintf(b, "byte(%q)\n", t)
case []byte: // []uint8
- fmt.Fprintf(b, "\n[]byte(%q)", t)
+ fmt.Fprintf(b, "[]byte(%q)\n", t)
default:
panic(fmt.Sprintf("unsupported type: %T", t))
}