]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: fix panic when Value.IsNil is called for UnsafePointer
authorAndrew Bonventre <andybons@golang.org>
Sun, 23 Dec 2018 21:48:38 +0000 (16:48 -0500)
committerAndrew Bonventre <andybons@golang.org>
Mon, 24 Dec 2018 01:23:25 +0000 (01:23 +0000)
UnsafePointer is a valid type kind to call IsNil on.

Fixes #29381

Change-Id: Iaf65d582c67f4be52cd1885badf40f174920500b
Reviewed-on: https://go-review.googlesource.com/c/155797
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/reflect/all_test.go
src/reflect/value.go

index 4b215f120c963b04c265d95e645f8298e6f23cc0..10b52456f34eecaaba881a01b72f6db26c735ddd 100644 (file)
@@ -1009,6 +1009,7 @@ func TestIsNil(t *testing.T) {
                struct{ x func() bool }{},
                struct{ x chan int }{},
                struct{ x []string }{},
+               struct{ x unsafe.Pointer }{},
        }
        for _, ts := range doNil {
                ty := TypeOf(ts).Field(0).Type
index 8906febb9bf1a41ca56e7a0717ab662e80442f7f..7ae2dd8d1045526a4d3996929ef44a4bb7847ac5 100644 (file)
@@ -1031,7 +1031,7 @@ func (v Value) InterfaceData() [2]uintptr {
 func (v Value) IsNil() bool {
        k := v.kind()
        switch k {
-       case Chan, Func, Map, Ptr:
+       case Chan, Func, Map, Ptr, UnsafePointer:
                if v.flag&flagMethod != 0 {
                        return false
                }