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

cmd/cgo: segfaults when resolving C.enum_* functions #12160

Closed
g2p opened this issue Aug 16, 2015 · 4 comments
Closed

cmd/cgo: segfaults when resolving C.enum_* functions #12160

g2p opened this issue Aug 16, 2015 · 4 comments
Milestone

Comments

@g2p
Copy link

g2p commented Aug 16, 2015

main.go

package main
// void enum_things(void) {}
import "C"

func main() {
    C.enum_things()
}

go build main.go

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x40f0f6]

goroutine 1 [running]:
main.(*Package).rewriteRef(0xc8200762a0, 0xc82007c080)
    …git/go/src/cmd/cgo/gcc.go:610 +0x1466
main.(*Package).Translate(0xc8200762a0, 0xc82007c080)
    …git/go/src/cmd/cgo/gcc.go:170 +0x197
main.main()
    …git/go/src/cmd/cgo/main.go:269 +0x1059
@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Aug 16, 2015
@ianlancetaylor
Copy link
Contributor

There are some special prefixes documented at https://golang.org/cmd/cgo , so this isn't going to work as you hope. But obviously cgo should not crash.

@ianlancetaylor ianlancetaylor changed the title cgo segfaults when resolving C.enum_* functions cmd/cgo: segfaults when resolving C.enum_* functions Aug 16, 2015
@gopherbot
Copy link

CL https://golang.org/cl/15264 mentions this issue.

ianlancetaylor pushed a commit that referenced this issue Oct 5, 2015
cgo panics in Package.rewriteRef for:

var a = C.enum_test(1)
or
p := new(C.enum_test)

when the corresponding enum type is not defined.

Check nil values for Type fields and issue a proper
error instead.

Fixes #11097
Updates #12160

Change-Id: I5821d29097ef0a36076ec5273125b09846c7d832
Reviewed-on: https://go-review.googlesource.com/15264
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@rsc
Copy link
Contributor

rsc commented Oct 16, 2015

Why did CL 15264 only update this issue? It seems fixed. I don't think we should try to distinguish alternate meanings for the special syntaxes like C.enum_x.

@ianlancetaylor
Copy link
Contributor

I agree. This is as fixed as it is going to get.

@golang golang locked and limited conversation to collaborators Oct 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants