Skip to content

Commit

Permalink
reflect: fix panic when Value.IsNil is called for UnsafePointer
Browse files Browse the repository at this point in the history
UnsafePointer is a valid type kind to call IsNil on.

Fixes golang#29381

Change-Id: Iaf65d582c67f4be52cd1885badf40f174920500b
Reviewed-on: https://go-review.googlesource.com/c/155797
Run-TryBot: Andrew Bonventre <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Keith Randall <[email protected]>
  • Loading branch information
andybons committed Dec 24, 2018
1 parent 97d5cb2 commit 3b66c00
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/reflect/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/reflect/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 3b66c00

Please sign in to comment.