Skip to content

Initialize nil pointers before UnmarshalText - #233

Open
jaideeppyne wants to merge 1 commit into
kelseyhightower:masterfrom
jaideeppyne:fix/nil-pointer-textunmarshaler
Open

jaideeppyne wants to merge 1 commit into
kelseyhightower:masterfrom
jaideeppyne:fix/nil-pointer-textunmarshaler

Conversation

@jaideeppyne

Copy link
Copy Markdown

Summary

processField invoked encoding.TextUnmarshaler (and Decode/Set) on nil pointer values. Slice elements such as []*T and unset *T fields therefore panicked:

panic: runtime error: invalid memory address or nil pointer dereference

Nil pointers are now allocated before those methods run, matching the existing allocation that already happened later for non-interface pointer fields.

Fixes #157

Test

TestNilPointerTextUnmarshaler covers a []*T slice and a nil *T field whose *T implements UnmarshalText. It panicked before this change.

go test -count=1 .

Slice elements and fields typed as pointers to a TextUnmarshaler were
left nil, so UnmarshalText ran on a nil receiver and panicked.

Fixes kelseyhightower#157
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

envconfig does not initialize pointer type which implements TextUnmarshaler

1 participant