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

encoding/json: Marshal/Unmarshal shouldn't accept a double pointer #9142

Closed
OneOfOne opened this issue Nov 20, 2014 · 3 comments

Comments

Projects
None yet
4 participants
@OneOfOne
Copy link
Contributor

commented Nov 20, 2014

What does 'go version' print?
go version devel +6d7a9c796f88 Fri Nov 14 12:08:46 2014 -0500 linux/amd64
and the playground.

What steps reproduce the problem?
http://play.golang.org/p/tDU_IzwVFg

What happened?
It runs fine

What should have happened instead?
It should panic or return an error because we're passing a pointer to a nil pointer and
reassigning it.
@minux

This comment has been minimized.

Copy link
Member

commented Nov 20, 2014

Comment 1:

why should that be forbidden?
the docs doesn't say double indirection is invalid.
besides, it's consistent with encoding/gob.
@OneOfOne

This comment has been minimized.

Copy link
Contributor Author

commented Nov 21, 2014

Comment 2:

My understanding is it assigns a new pointer a nil pointer:
var s *Struct
x := &s // address of a nil pointer
*x = &Struct{} // assigns "nil" *s to a new value
I guess my C/C++ background just sees it weird.
I didn't assign it to encoding/json in the summary because I think it's a general/spec
bug, or at least it should be but I could be wrong.
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Nov 21, 2014

Comment 3:

I can't see anything wrong here.

Status changed to WorkingAsIntended.

@golang golang locked and limited conversation to collaborators Jun 25, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.