Using go1.7.4, but seems to have been present since go1.3
OS: Linux carbonite 3.13.0-37-generic #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Consider the following code:
type X struct {
A, B []byte
}
func (x X) Print() {
fmt.Printf("%p %p\n", x.A, x.B)
}
func caller(f func()) {
f()
}
func main() {
caller(X{A: []byte{}}.Print)
}
Currently this prints:
I expect this to print:
The Print method is declared on a value receiver. In the main function we define a struct literal of type X and explicitly set the A field to be some value, but we expect the B field to be implicitly be zeroed out. The Print method of that struct literal is passed to another function as a callback.
When the callback is called, it shows that the B field is not zeroed and contains a pointer to some arbitrary piece of memory.
\cc @randall77 @dr2chase @paranoiacblack
Using
go1.7.4, but seems to have been present sincego1.3OS:
Linux carbonite 3.13.0-37-generic #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 x86_64 x86_64 x86_64 GNU/LinuxConsider the following code:
Currently this prints:
I expect this to print:
The
Printmethod is declared on a value receiver. In the main function we define a struct literal of type X and explicitly set the A field to be some value, but we expect the B field to be implicitly be zeroed out. ThePrintmethod of that struct literal is passed to another function as a callback.When the callback is called, it shows that the B field is not zeroed and contains a pointer to some arbitrary piece of memory.
\cc @randall77 @dr2chase @paranoiacblack