Skip to content

Commit f85c282

Browse files
heschigopherbot
authored andcommitted
internal/testpty: fix error handling
When calling a c library function, you discover that an error has occurred, typically by looking at the return value of the function. Only after that can you use errno to figure out the cause of the error. Nothing about cgo changes that story -- you still have to look at the result before checking the error that represents errno. If not you can get false errors if the function happens to leak a non-zero errno. Fix testpty to check errors correctly. Change-Id: Idb95f8dd6a8ed63f653190c2e722e742cf50542b Reviewed-on: https://go-review.googlesource.com/c/go/+/463397 Run-TryBot: Heschi Kreinick <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Auto-Submit: Heschi Kreinick <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent a896219 commit f85c282

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/internal/testpty/pty_cgo.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import "os"
1818

1919
func open() (pty *os.File, processTTY string, err error) {
2020
m, err := C.posix_openpt(C.O_RDWR)
21-
if err != nil {
21+
if m < 0 {
2222
return nil, "", ptyError("posix_openpt", err)
2323
}
24-
if _, err := C.grantpt(m); err != nil {
24+
if res, err := C.grantpt(m); res < 0 {
2525
C.close(m)
2626
return nil, "", ptyError("grantpt", err)
2727
}
28-
if _, err := C.unlockpt(m); err != nil {
28+
if res, err := C.unlockpt(m); res < 0 {
2929
C.close(m)
3030
return nil, "", ptyError("unlockpt", err)
3131
}

0 commit comments

Comments
 (0)