fix: nil-pointer panic from custom type function
A DecodeCustomTypeFunc returning nil to mean "leave this pointer field unset" panicked in reflect.Value.Set, since reflect.ValueOf(nil) is the invalid zero Value. Guard against a nil return before Set. This is the panic from #68/#69: the earlier fix routed pointer fields through the generic Ptr recursion instead of guarding nil, which discarded a custom function's own populated pointer result and had to be reverted. Guarding val == nil directly fixes the panic without touching the case that broke.
This commit is contained in:
1 parent
3b027bdc88
commit
8a7336f727
3 files changed
+147
No files matched your search
@@ -199,6 +199,14 @@ func (d *decoder) setFieldByType(current reflect.Value, namespace []byte, idx in
|
||||
return
|
||||
}
|
||||
|
||||
// A custom function returning a nil interface has no value to
|
||||
// set, eg. to signal "leave this field at its zero value" for
|
||||
// an empty input; reflect.ValueOf(nil) is the invalid zero
|
||||
// Value and Set would panic on it.
|
||||
if val == nil {
|
||||
return
|
||||
}
|
||||
|
||||
v.Set(reflect.ValueOf(val))
|
||||
set = true
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user