Skip to content

Commit

Permalink
[tailscale1.16] reflect: improve panic when MapIter has no associated…
Browse files Browse the repository at this point in the history
… map Value

it := new(reflect.MapIter)
it.Next()

This generates a nil pointer dereference panic from reflect.Value.pointer.
Generate a clearer panic.

For golang#46293

(cherry picked from golang.org/cl/321890)

Change-Id: I32a22c797e1ba3a7b4e70b38ceb4dedb44d264fa
  • Loading branch information
josharian committed May 24, 2021
1 parent 5740ae9 commit bf1d94b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/reflect/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,9 @@ func (it *MapIter) SetValue(dst Value) {
// entry. It returns false when the iterator is exhausted; subsequent
// calls to Key, Value, or Next will panic.
func (it *MapIter) Next() bool {
if !it.m.IsValid() {
panic("MapIter.Next called on an iterator that does not have an associated map Value")
}
if it.it == nil {
it.it = unsafe.Pointer(&it.hiter)
mapiterinit(it.m.typ, it.m.pointer(), it.it)
Expand Down

0 comments on commit bf1d94b

Please sign in to comment.