You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When passing a pointer to an element in an array or slice, the Go memory in question is the entire array or the entire backing array of the slice.
However, when we pass such a pointer as type unsafe.Pointer (rather than a concrete pointer type) and the slice is backed by some field of a larger struct type (such as a bytes.Buffer) cgo ends up checking the entire struct instead of just the backing array, producing false positives.
(Passing a slice as unsafe.Pointer can occasionally occur naturally when using SWIG, for example when wrapping a []byte to a std::string_view.)
We should either document the type-based caveat or weaken the check to avoid reporting this as an error.
~$ go version
go version devel +3a395e2283 Fri Nov 17 19:00:41 2017 +0000 linux/amd64
~$ go run src/cgobuf/main.go
panic: runtime error: cgo argument has Go pointer to Go pointer
goroutine 1 [running]:
main.main.func1(0xc42009e020)
/home/bcmills/src/cgobuf/main.go:22 +0x48
main.main()
/home/bcmills/src/cgobuf/main.go:22 +0xa6
exit status 2
According to the current cgo pointer-passing rules:
However, when we pass such a pointer as type
unsafe.Pointer
(rather than a concrete pointer type) and the slice is backed by some field of a larger struct type (such as abytes.Buffer
) cgo ends up checking the entire struct instead of just the backing array, producing false positives.(Passing a slice as
unsafe.Pointer
can occasionally occur naturally when using SWIG, for example when wrapping a[]byte
to astd::string_view
.)We should either document the type-based caveat or weaken the check to avoid reporting this as an error.
src/cgobuf/main.go:
(CC @ianlancetaylor )
The text was updated successfully, but these errors were encountered: