gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source
https://gno.land/
Other
875 stars 355 forks source link

`println` panics on byte pointer types #1575

Closed deelawn closed 5 months ago

deelawn commented 7 months ago

A panic occurs when trying to print a pointer to a single byte value using println.

This can be produced by running:

package main

func main() {
    c := []byte("A")
    println(&c[0])
}

Trace:

goroutine 19 [running]:
runtime/debug.Stack()
    /usr/local/go/src/runtime/debug/stack.go:24 +0x5e
runtime/debug.PrintStack()
    /usr/local/go/src/runtime/debug/stack.go:16 +0x13
github.com/gnolang/gno/gnovm/tests.RunFileTest.func1.1()
    /Users/dylan/deelawn/gnoland/gno2/gno/gnovm/tests/file.go:136 +0x157
panic({0x17582e0?, 0x1a31990?})
    /usr/local/go/src/runtime/panic.go:914 +0x21f
github.com/gnolang/gno/gnovm/pkg/gnolang.(*TypedValue).ProtectedSprint(0xc000437bc0, 0xc00019d260, 0x0)
    /Users/dylan/deelawn/gnoland/gno2/gno/gnovm/pkg/gnolang/values_string.go:341 +0xdde
github.com/gnolang/gno/gnovm/pkg/gnolang.TypedValue.ProtectedString({{0x1a3b930, 0x1a30778}, {0x1a37918, 0xc0003fb1a0}, {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...}}, ...)
...

Note that this does not occur if c is initialized differently:

package main

func main() {
    c := []byte{'A'}
    println(&c[0])
}

This seems to be related to #1569 where the behavior changes depending how the byte slice was initialized. However, I think that the solution here may be to account for the DataByteValue type in TypedValue's ProtectedSprint method.

deelawn commented 6 months ago

This will be fixed by #1601