Skip to content

Files

Latest commit

 

History

History
42 lines (28 loc) · 769 Bytes

cgocall.md

File metadata and controls

42 lines (28 loc) · 769 Bytes

Pattern: Invalid use of cgo

Issue: -

Description

This rule checks for types that may not be passed to cgo calls.

Example of incorrect code:

import "C"

import "unsafe"

func CgoTests() {
	var c chan bool
	C.f(*(*unsafe.Pointer)(unsafe.Pointer(&c))) // embedded pointer
	C.f(unsafe.Pointer(&c))                     // embedded pointer
}

Example of correct code:

import "C"

import "unsafe"

func CgoTests() {
	var i int
	C.f(*(*unsafe.Pointer)(unsafe.Pointer(&i)))
	C.f(unsafe.Pointer(&i))
}

Further Reading