func lock(t testing.TB, filename string) (unlock func()) {
f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0600)
require.NoError(t, err)
for {
err = unix.Flock(int(f.Fd()), unix.LOCK_EX)
if !errors.Is(err, unix.EINTR) {
break
}
}
require.NoError(t, err)
return func() {
_ = f.Close()
}
}
G115 (CWE-190): integer overflow conversion uintptr -> int (Confidence: MEDIUM, Severity: HIGH)
50: for {
> 51: err = unix.Flock(int(f.Fd()), unix.LOCK_EX)
52: if !errors.Is(err, unix.EINTR) {
However, this is the correct way to operate on raw file descriptors. See lots of examples in Go source itself: https://github.com/search?q=repo%3Agolang%2Fgo+%2F%28unix%7Csyscall%29%5C.%5Cw%2B%5C%28int%5C%28%2F&type=code
However, this is the correct way to operate on raw file descriptors. See lots of examples in Go source itself: https://github.com/search?q=repo%3Agolang%2Fgo+%2F%28unix%7Csyscall%29%5C.%5Cw%2B%5C%28int%5C%28%2F&type=code