From 839d8d17a7c2ffc7bb605104bd5c163d0626d02d Mon Sep 17 00:00:00 2001 From: Pekka Vainio Date: Tue, 3 Mar 2026 15:32:26 +0200 Subject: [PATCH] fix: handle -1 from syscall.Read --- serial_posix.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/serial_posix.go b/serial_posix.go index 6d25b2d..d20ff95 100644 --- a/serial_posix.go +++ b/serial_posix.go @@ -111,6 +111,14 @@ func (p *port) Read(b []byte) (n int, err error) { return } n, err = syscall.Read(fd, b) + if n < 0 { + // underlying syscall.Read returns -1 on error, but we want to return 0 to be consistent with io.Reader interface. + if err == nil { + // This should not happen, but just in case. + err = fmt.Errorf("serial: read returned %v without error", n) + } + n = 0 + } return }