From 3b66c00857ff77f8acfc3e6e9491dda3677858a4 Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Sun, 23 Dec 2018 16:48:38 -0500 Subject: [PATCH] reflect: fix panic when Value.IsNil is called for UnsafePointer 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 TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/reflect/all_test.go | 1 + src/reflect/value.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index 4b215f120c963b..10b52456f34eec 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -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 diff --git a/src/reflect/value.go b/src/reflect/value.go index 8906febb9bf1a4..7ae2dd8d104552 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -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 }