1
0
mirror of https://github.com/golang/go synced 2024-09-30 13:18:34 -06:00

cmd/vet: cgo: emit no error for calls to C.CBytes

Fixes issue golang/go#17563

Change-Id: Ibb41ea9419907193526cc601f6afd07d8689b1fe
Reviewed-on: https://go-review.googlesource.com/31810
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Alan Donovan 2016-10-24 11:00:19 -04:00
parent 2a3db5c017
commit 07a22dbd34
2 changed files with 7 additions and 0 deletions

View File

@ -38,6 +38,11 @@ func checkCgoCall(f *File, node ast.Node) {
return return
} }
// A call to C.CBytes passes a pointer but is always safe.
if sel.Sel.Name == "CBytes" {
return
}
for _, arg := range x.Args { for _, arg := range x.Args {
if !typeOKForCgoCall(cgoBaseType(f, arg)) { if !typeOKForCgoCall(cgoBaseType(f, arg)) {
f.Badf(arg.Pos(), "possibly passing Go type with embedded pointer to C") f.Badf(arg.Pos(), "possibly passing Go type with embedded pointer to C")

View File

@ -51,4 +51,6 @@ func CgoTests() {
var st2 struct{ i int } var st2 struct{ i int }
C.f(*(*unsafe.Pointer)(unsafe.Pointer(&st2))) C.f(*(*unsafe.Pointer)(unsafe.Pointer(&st2)))
C.f(unsafe.Pointer(&st2)) C.f(unsafe.Pointer(&st2))
C.CBytes([]byte("hello"))
} }