diff options
| author | Didier Spezia <didier.06@gmail.com> | 2015-10-03 15:50:45 +0000 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2015-10-05 22:37:07 +0000 |
| commit | 9c258c6aa6880268a0be9f2e90ea11f9e4ded150 (patch) | |
| tree | 461f0301e83d2d6acdbdf4aff283e647bba2004f /misc/cgo/errors | |
| parent | 4a6326e7b5f326e6079073fb843b4ab096cbf652 (diff) | |
| download | go-9c258c6aa6880268a0be9f2e90ea11f9e4ded150.tar.xz | |
cmd/cgo: fix panic on references to non-existing C types
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>
Diffstat (limited to 'misc/cgo/errors')
| -rw-r--r-- | misc/cgo/errors/issue11097a.go | 15 | ||||
| -rw-r--r-- | misc/cgo/errors/issue11097b.go | 15 | ||||
| -rwxr-xr-x | misc/cgo/errors/test.bash | 2 |
3 files changed, 32 insertions, 0 deletions
diff --git a/misc/cgo/errors/issue11097a.go b/misc/cgo/errors/issue11097a.go new file mode 100644 index 0000000000..4508213cb4 --- /dev/null +++ b/misc/cgo/errors/issue11097a.go @@ -0,0 +1,15 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +/* +//enum test { foo, bar }; +*/ +import "C" + +func main() { + var a = C.enum_test(1) // ERROR HERE + _ = a +} diff --git a/misc/cgo/errors/issue11097b.go b/misc/cgo/errors/issue11097b.go new file mode 100644 index 0000000000..68c5c7c64c --- /dev/null +++ b/misc/cgo/errors/issue11097b.go @@ -0,0 +1,15 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +/* +//enum test { foo, bar }; +*/ +import "C" + +func main() { + p := new(C.enum_test) // ERROR HERE + _ = p +} diff --git a/misc/cgo/errors/test.bash b/misc/cgo/errors/test.bash index c880ad65c2..25ab249940 100755 --- a/misc/cgo/errors/test.bash +++ b/misc/cgo/errors/test.bash @@ -31,6 +31,8 @@ check err2.go check err3.go check issue7757.go check issue8442.go +check issue11097a.go +check issue11097b.go rm -rf errs _obj exit 0 |
