From f985833dec19b0147db3c5c33d3bf0181891d458 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 16 Feb 2022 10:52:01 -0500 Subject: testing: panic in Fuzz if the function returns a value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise, the behavior of a fuzz target that returns an error could be confusing. Fuzz is already documented to require a function “with no return value”, so this fixes the implementation to match the existing documentation. Fixes #51222 Change-Id: I44ca7ee10960214c92f5ac066ac8484c8bb9cd6f Reviewed-on: https://go-review.googlesource.com/c/go/+/386175 Trust: Bryan Mills Run-TryBot: Bryan Mills Reviewed-by: Robert Findley Reviewed-by: Nooras Saba‎ TryBot-Result: Gopher Robot --- src/testing/fuzz.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/testing') diff --git a/src/testing/fuzz.go b/src/testing/fuzz.go index e1d7544f7a..b5e1339deb 100644 --- a/src/testing/fuzz.go +++ b/src/testing/fuzz.go @@ -227,6 +227,9 @@ func (f *F) Fuzz(ff any) { if fnType.NumIn() < 2 || fnType.In(0) != reflect.TypeOf((*T)(nil)) { panic("testing: fuzz target must receive at least two arguments, where the first argument is a *T") } + if fnType.NumOut() != 0 { + panic("testing: fuzz target must not return a value") + } // Save the types of the function to compare against the corpus. var types []reflect.Type -- cgit v1.3-5-g9baa