mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/json: fix panic unmarshaling into non-nil interface value
Fixes #3614. R=golang-dev, adg CC=golang-dev https://golang.org/cl/6306051
This commit is contained in:
parent
8022a1a588
commit
09b736a2ab
2 changed files with 53 additions and 2 deletions
|
|
@ -273,9 +273,14 @@ func (d *decodeState) indirect(v reflect.Value, decodingNull bool) (Unmarshaler,
|
|||
_, isUnmarshaler = v.Interface().(Unmarshaler)
|
||||
}
|
||||
|
||||
// Load value from interface, but only if the result will be
|
||||
// usefully addressable.
|
||||
if iv := v; iv.Kind() == reflect.Interface && !iv.IsNil() {
|
||||
v = iv.Elem()
|
||||
continue
|
||||
e := iv.Elem()
|
||||
if e.Kind() == reflect.Ptr && !e.IsNil() && (!decodingNull || e.Elem().Kind() == reflect.Ptr) {
|
||||
v = e
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
pv := v
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue