Not checking for nil might lead to nil pointer dereference
rzajac opened this issue ยท 4 comments
rzajac commented
Lines 167 to 173 in 8285576
The f
should be checked for nil
before it is used in closure.
zak905 commented
Hi @rzajac, do you have an example that triggers a panic ? I think that if f
is nil
than v
will be nil
as well, and therefore the closure will return always "null" value, so f(v.Elem())
statement will not be reached
I tried to trigger the case you mentionned but I was not able to
func TestNilPointerDeference(t *testing.T) {
type C struct {
R int `schema:"R"`
}
type B struct {
C *C `schema:"C"`
}
b := B{C: (*C)(nil)}
encoder := NewEncoder()
vals := url.Values{}
if err := encoder.Encode(b, vals); err != nil {
t.Fatalf(err.Error())
}
}
The test is passing without errors.
zak905 commented
sure thing!