aboutsummaryrefslogtreecommitdiff
path: root/src/reflect/all_test.go
diff options
context:
space:
mode:
authorPaschalis Tsilias <paschalis.tsilias@gmail.com>2021-01-15 17:40:20 +0200
committerIan Lance Taylor <iant@golang.org>2021-03-15 23:49:28 +0000
commitd7cc2f1d7c60b51c600c7d0c808610985dcd9b0c (patch)
tree4fd4a880eea80344f89c1215786977b4773dbc8a /src/reflect/all_test.go
parent661f3f15d5c96704a2fe9e91c6c40f73ff896606 (diff)
downloadgo-d7cc2f1d7c60b51c600c7d0c808610985dcd9b0c.tar.gz
go-d7cc2f1d7c60b51c600c7d0c808610985dcd9b0c.zip
reflect: panic if ArrayOf is called with negative length
Since we cannot change the signature of reflect.ArrayOf to return an error, we panic instead of producing a wrong result. Fixes #43603 Change-Id: I23915df8d190f35af4d00ab86768868cd621e839 Reviewed-on: https://go-review.googlesource.com/c/go/+/284136 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/reflect/all_test.go')
-rw-r--r--src/reflect/all_test.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go
index 35cc469d74..accda7fa74 100644
--- a/src/reflect/all_test.go
+++ b/src/reflect/all_test.go
@@ -4636,6 +4636,14 @@ func TestArrayOfDirectIface(t *testing.T) {
}
}
+// Ensure passing in negative lengths panics.
+// See https://golang.org/issue/43603
+func TestArrayOfPanicOnNegativeLength(t *testing.T) {
+ shouldPanic("reflect: negative length passed to ArrayOf", func() {
+ ArrayOf(-1, TypeOf(byte(0)))
+ })
+}
+
func TestSliceOf(t *testing.T) {
// check construction and use of type not in binary
type T int