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

Panic during compilation if function returns structure with unset slice #949

Closed
alexvanin opened this issue May 13, 2020 · 3 comments
Closed
Assignees
Labels
bug Something isn't working compiler Go smart contract compiler

Comments

@alexvanin
Copy link
Contributor

I run this code:

package foo

type Foo struct {
	x []int
}

func NewFoo() Foo {
	return Foo{}
}

func Main() int {
	foo := NewFoo()
	if foo.x == nil {
		return 1
	}

	return 0
}

I expect to get 1 but got panic during compilation. If I use return Foo{x:nil} panic does not occur and I got correct result.

Panic message:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x8098fb]

goroutine 19 [running]:
testing.tRunner.func1.1(0x891a80, 0xcd5eb0)
	/snap/go/current/src/testing/testing.go:940 +0x2f5
testing.tRunner.func1(0xc0000d37a0)
	/snap/go/current/src/testing/testing.go:943 +0x3f9
panic(0x891a80, 0xcd5eb0)
	/snap/go/current/src/runtime/panic.go:969 +0x166
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).emitLoadConst(0xc0000e9e00, 0x0, 0x0, 0x0, 0x0, 0x0)
	/home/alexvanin/Project/Neo/neo-go/pkg/compiler/codegen.go:115 +0x4b
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).convertStruct(0xc0000e9e00, 0xc0000acc80)
	/home/alexvanin/Project/Neo/neo-go/pkg/compiler/codegen.go:1211 +0x25a
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).Visit(0xc0000e9e00, 0x9c4be0, 0xc0000acc80, 0x0, 0x0)
	/home/alexvanin/Project/Neo/neo-go/pkg/compiler/codegen.go:568 +0x1382
go/ast.Walk(0x9c1780, 0xc0000e9e00, 0x9c4be0, 0xc0000acc80)
	/snap/go/current/src/go/ast/walk.go:52 +0x66
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).Visit(0xc0000e9e00, 0x9c52a0, 0xc0000b7060, 0xc000099660, 0x0)
	/home/alexvanin/Project/Neo/neo-go/pkg/compiler/codegen.go:437 +0x33cf
go/ast.Walk(0x9c1780, 0xc0000e9e00, 0x9c52a0, 0xc0000b7060)
	/snap/go/current/src/go/ast/walk.go:52 +0x66
go/ast.walkStmtList(0x9c1780, 0xc0000e9e00, 0xc000099410, 0x1, 0x1)
	/snap/go/current/src/go/ast/walk.go:32 +0x9e
go/ast.Walk(0x9c1780, 0xc0000e9e00, 0x9c49e0, 0xc00009de00)
	/snap/go/current/src/go/ast/walk.go:224 +0x1adf
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).convertFuncDecl(0xc0000e9e00, 0x9c4de0, 0xc0000ee180, 0xc00009de30)
	/home/alexvanin/Project/Neo/neo-go/pkg/compiler/codegen.go:263 +0x542
github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).compile(0xc0000e9e00, 0xc0000b73a0, 0xc0000c0370, 0xc0000a5230, 0x0)
	/home/alexvanin/Project/Neo/neo-go/pkg/compiler/codegen.go:1317 +0x490
github.com/nspcc-dev/neo-go/pkg/compiler.CodeGen(0xc0000b73a0, 0xc0000b6f20, 0xc0000b73a0, 0x0, 0x0, 0xc00009dc01, 0xc0000b6f20)
	/home/alexvanin/Project/Neo/neo-go/pkg/compiler/codegen.go:1345 +0x289
github.com/nspcc-dev/neo-go/pkg/compiler.CompileWithDebugInfo(0x9c1d60, 0xc0000b6f20, 0x7f8a774707d0, 0x0, 0x40e0e6, 0xc0000b6ee0, 0x20, 0x20)
	/home/alexvanin/Project/Neo/neo-go/pkg/compiler/compiler.go:78 +0x90
github.com/nspcc-dev/neo-go/pkg/compiler.Compile(...)
	/home/alexvanin/Project/Neo/neo-go/pkg/compiler/compiler.go:64
github.com/nspcc-dev/neo-go/pkg/compiler_test.vmAndCompileInterop(0xc0000d37a0, 0x92f6bc, 0xae, 0xc0000a5150, 0xc000044738)
	/home/alexvanin/Project/Neo/neo-go/pkg/compiler/vm_test.go:66 +0x10b
github.com/nspcc-dev/neo-go/pkg/compiler_test.vmAndCompile(...)
	/home/alexvanin/Project/Neo/neo-go/pkg/compiler/vm_test.go:56
github.com/nspcc-dev/neo-go/pkg/compiler_test.eval(0xc0000d37a0, 0x92f6bc, 0xae, 0x90bb00, 0xc0000b6ee0)
	/home/alexvanin/Project/Neo/neo-go/pkg/compiler/vm_test.go:33 +0x49
github.com/nspcc-dev/neo-go/pkg/compiler_test.TestForLoopRangeGlobalIndex1(0xc0000d37a0)
	/home/alexvanin/Project/Neo/neo-go/pkg/compiler/for_test.go:486 +0x7d
testing.tRunner(0xc0000d37a0, 0x936d68)
	/snap/go/current/src/testing/testing.go:991 +0xdc
created by testing.(*T).Run
	/snap/go/current/src/testing/testing.go:1042 +0x357

@alexvanin
Copy link
Contributor Author

branch: master-2.x
version: 0.74.1-pre-156-gc85e77e1

@roman-khimov roman-khimov added the bug Something isn't working label May 13, 2020
@roman-khimov roman-khimov added this to the v0.75.0 milestone May 13, 2020
@fyrchik
Copy link
Contributor

fyrchik commented May 14, 2020

See my first comment to #952.

@fyrchik
Copy link
Contributor

fyrchik commented Jun 11, 2020

Fixed via #952 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working compiler Go smart contract compiler
Projects
None yet
Development

No branches or pull requests

3 participants