-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive - cgo - block starting/ending with whitespaces #162
Comments
Thanks for this! CGO support was just added but not by me so I'm not 100% sure why this is but let's figure it out!
I tried to reproduce this code as a runnable/compiling example. Show codepackage main
// #include <stdio.h>
// #include <stdint.h>
// uint8_t hello(uint8_t a, uint8_t b, uint8_t c) {
// printf("Hello from C: %d, %d, %d\n", a, b, c);
//
// return 0;
//}
import "C"
import "errors"
func main() {
PrintCHello()
}
func PrintCHello() error {
ret := C.hello(
C.uint8_t(1),
C.uint8_t(2),
C.uint8_t(3),
)
if ret != 0 {
return errors.New("error")
}
return nil
} However that doesn't produce your result: › wsl ./ And the generated code does very few changes not causing any issues for the linter: › go tool cgo -godefs main.go Show code// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs main.go
package main
import "errors"
func main() {
PrintCHello()
}
func PrintCHello() error {
ret := _Cfunc_hello(
uint8(1),
uint8(2),
uint8(3),
)
if ret != 0 {
return errors.New("error")
}
return nil
} |
I've tried something similar and indeed, in-line C-code with a similar function does not produce the same issues. I've tried both Running func (e *Ecopoint) SetEventAlarm(alarm EventAlarm) error {
ret := _Cfunc_ecopointSetEventAlarm(
e.instance,
uint8(alarm.Count), uint8(alarm.BaseTime), uint8(alarm.LockTime), uint16(alarm.Threshold),
)
if ret != 0 {
return getLastError()
}
return nil
} Also nothing shocking... /*
#cgo pkg-config: ecopoint
#include <stdlib.h>
#include <ecopointlib_24-04-2023.h>
*/ The ecopointlib we are using is proprietary, so I am unfortunately not allow to share it and neither do I know the implementation of the called function. I will try to find some time in the coming days to reproduce it using open source libs. |
For the newest wsl (v4.5.0), given this code snippet:
I'm getting the following false positives:
Pointing to the start and end of the
ret
block.I'm still trying to isolate the issue, but I've not been able to produce it yet outside of our project.
The text was updated successfully, but these errors were encountered: