1
0
mirror of https://github.com/golang/go synced 2024-11-14 15:20:43 -07:00
go/src/reflect
Daniel Martí 9bced47706 reflect: don't panic in ArrayOf if elem size is 0
We do a division by the elem type size to check if the array size would
be too large for the virtual address space. This is a silly check if the
size is 0, but the problem is that it means a division by zero and a
panic.

Since arrays of empty structs are valid in a regular program, make them
also work in reflect.

Use a separate, explicit test with struct{}{} to make sure the test for
a zero-sized type is not confused with the rest.

Fixes #20313.

Change-Id: I47b8b87e6541631280b79227bdea6a0f6035c9e0
Reviewed-on: https://go-review.googlesource.com/43131
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-05-10 13:44:53 +00:00
..
all_test.go reflect: don't panic in ArrayOf if elem size is 0 2017-05-10 13:44:53 +00:00
asm_386.s all: make copyright headers consistent with one space after period 2016-03-01 23:34:33 +00:00
asm_amd64.s all: make copyright headers consistent with one space after period 2016-03-01 23:34:33 +00:00
asm_amd64p32.s all: make copyright headers consistent with one space after period 2016-03-01 23:34:33 +00:00
asm_arm64.s all: make copyright headers consistent with one space after period 2016-03-01 23:34:33 +00:00
asm_arm.s all: make copyright headers consistent with one space after period 2016-03-01 23:34:33 +00:00
asm_mips64x.s all: make copyright headers consistent with one space after period 2016-03-01 23:34:33 +00:00
asm_mipsx.s reflect: add support for GOARCH=mips{,le} 2016-11-03 23:01:05 +00:00
asm_ppc64x.s all: make copyright headers consistent with one space after period 2016-03-01 23:34:33 +00:00
asm_s390x.s reflect: add s390x support 2016-04-06 04:23:06 +00:00
deepequal.go reflect: fix DeepEqual for some cyclic corner cases 2016-10-24 15:20:23 +00:00
example_test.go reflect: add example for StructOf 2016-12-06 20:18:12 +00:00
export_test.go reflect: unexported fields are tied to a package 2016-11-10 14:06:23 +00:00
makefunc.go runtime: clean up and improve reflect.methodValue comments 2016-12-19 21:02:53 +00:00
set_test.go reflect: recognize unnamed directional channels 2016-03-04 20:34:30 +00:00
swapper.go reflect: add Swapper func 2016-09-30 20:26:54 +00:00
tostring_test.go
type.go reflect: don't panic in ArrayOf if elem size is 0 2017-05-10 13:44:53 +00:00
value.go reflect: add MakeMapWithSize for creating maps with size hint 2017-04-04 20:01:43 +00:00