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:
parent
2a3db5c017
commit
07a22dbd34
@ -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")
|
||||||
|
2
src/cmd/vet/testdata/cgo.go
vendored
2
src/cmd/vet/testdata/cgo.go
vendored
@ -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"))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user