mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
661f3f15d5
commit
d7cc2f1d7c
2 changed files with 30 additions and 18 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue