Skip to content

Commit cc94103

Browse files
author
Étienne Miret
committed
Fix error detection in pfring.NewRing
The cgo documentation states: > Any C function (even void functions) may be called in a multiple > assignment context to retrieve both the return value (if any) and the > C errno variable as an error See: <https://pkg.go.dev/cmd/cgo> Furthermore, the manpage for errno states: > The value in errno is significant only when the return value of the > call indicated an error (i.e., -1 from most system calls; -1 or NULL > from most library functions); a function that succeeds is allowed to > change errno. The value of errno is never set to zero by any system > call or library function. See: man 3 errno Therefore, I believe the value of err MUST be ignored unless we have something else that reports an error.
1 parent 32ee382 commit cc94103

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pfring/pfring.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func NewRing(device string, snaplen uint32, flags Flag) (ring *Ring, _ error) {
9999
defer C.free(unsafe.Pointer(dev))
100100

101101
cptr, err := C.pfring_open(dev, C.u_int32_t(snaplen), C.u_int32_t(flags))
102-
if cptr == nil || err != nil {
102+
if cptr == nil {
103103
return nil, fmt.Errorf("pfring NewRing error: %v", err)
104104
}
105105
ring = &Ring{cptr: cptr}

0 commit comments

Comments
 (0)