Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed panic on pointers to embedded structs #139

Merged
merged 2 commits into from
Aug 20, 2020
Merged

Conversation

morus12
Copy link
Contributor

@morus12 morus12 commented May 7, 2020

Summary of Changes

 type Example struct {
    *Embedded
     Field string
 }

When a struct contains a pointer to an embedded struct, the code panics because the fields in the embedded struct are not allocated.
Part of the stack trace:

reflect: indirection through nil pointer to embedded struct goroutine 90 [running]:
reflect.Value.FieldByIndex(0x1bbc4e0, 0xc0003e7ec0, 0x199, 0xc0002c6e40, 0x2, 0x2, 0x0, 0x1d93dc0, 0x1aeb9c0)
	/usr/local/go/src/reflect/value.go:876 +0x4f2
reflect.Value.FieldByName(0x1bbc4e0, 0xc0003e7ec0, 0x199, 0x1b54e80, 0x4, 0x199, 0x15afec3, 0xc0003e7eba)
	/usr/local/go/src/reflect/value.go:892 +0x116
github.com/gorilla/schema.(*Decoder).decode(0xc0002b9e40, 0x1b36ae0, 0xc0000d8280, 0x196, 0xc0004d0799, 0xc, 0xc0000e6ca8, 0x1, 0x1, 0xc0002b9e60, ...)
	/Users/grzegorzwyszyski/Workspace/gopath/pkg/mod/github.com/gorilla/schema@v1.1.0/decoder.go:185 +0x212
github.com/gorilla/schema.(*Decoder).decode(0xc0002b9e40, 0x1bf0600, 0xc00032e1e0, 0x199, 0xc0004d0799, 0xc, 0xc0000e6c80, 0x2, 0x2, 0xc0002b9e60, ...)
	/Users/grzegorzwyszyski/Workspace/gopath/pkg/mod/github.com/gorilla/schema@v1.1.0/decoder.go:213 +0x28aa
github.com/gorilla/schema.(*Decoder).Decode(0xc0002b9e40, 0x1b36a60, 0xc00032e1e0, 0xc00021f200, 0x2, 0x3b)
	/Users/grzegorzwyszyski/Workspace/gopath/pkg/mod/github.com/gorilla/schema@v1.1.0/decoder.go:80 +0x3c6

Panic can be reproduced using the test provided by this pull request.

@stale
Copy link

stale bot commented Jul 6, 2020

This issue has been automatically marked as stale because it hasn't seen a recent update. It'll be automatically closed in a few days.

@stale stale bot added the stale label Jul 6, 2020
@stale stale bot closed this Jul 13, 2020
@elithrar elithrar reopened this Aug 20, 2020
@stale stale bot removed the stale label Aug 20, 2020
@elithrar elithrar added the bug label Aug 20, 2020
@elithrar
Copy link
Contributor

Thanks @morus12

@elithrar elithrar merged commit 0cfe0ec into gorilla:master Aug 20, 2020
kirr pushed a commit to joomcode/schema that referenced this pull request Jul 30, 2021
* fixed panic on pointers to embedded structs

* don't alloc when it's already allocated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants