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/gob: mis-decodes pointers to int 0 to nil pointers #23498
Comments
gob doc:
So you're encoding an
. |
see #11119 |
Thanks, I understand why that's the case, but it's surprising (to me at least) that gob doesn't round-trip the struct back to the same thing as the original. The obvious workaround indeed is to use another layer of struct, but while that's easy in this case, it'd have been nice not to have to work out why the two things weren't equivalant. |
It surely can be surprising but, as Rob noted in the old issue I linked above, changes to the gob model at this point are pretty unlikely and there's not much to do other that label this as |
Change https://golang.org/cl/90695 mentions this issue: |
The problem is that vet complains about 0 as a Printf flag in some situations where fmt allows it but probably shouldn't. The two need to be brought in line, but it's too late in the release cycle. The situation is messy and should be resolved properly in 1.11. This CL is a simple fix to disable a spurious complaint for 1.10 that will be resolved in a more thorough way in 1.11. The workaround is just to be silent about flag 0, as suggested in issue 23605. Fixes #23605 Update #23498 Change-Id: Ice1a4f4d86845d70c1340a0a6430d74e5de9afd4 Reviewed-on: https://go-review.googlesource.com/90695 Run-TryBot: Rob Pike <r@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.9.2 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/pebers/go"
GORACE=""
GOROOT="/opt/tm/tools/go/1.9.2/usr/go"
GOTOOLDIR="/opt/tm/tools/go/1.9.2/usr/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="cc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build126697151=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
What did you do?
Round-tripped a struct with a pointer to an int with value 0 through gob (i.e. encoded then decoded).
e.g. https://play.golang.org/p/9LWD9cg04ni
What did you expect to see?
Decoded struct has a pointer to int 0 and hence matches the original.
What did you see instead?
Decoded struct has a nil pointer.
The text was updated successfully, but these errors were encountered: