From dab678ecf5dcb3eff345db8ac68ae6d7438f9d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Sun, 11 Jan 2015 17:46:43 +0100 Subject: [PATCH] fix: handle read errors correctly --- xxd.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/xxd.go b/xxd.go index f440d5d..d51f297 100644 --- a/xxd.go +++ b/xxd.go @@ -45,8 +45,11 @@ func XXD(r io.Reader, w io.Writer) error { r = bufio.NewReader(r) for { n, err := io.ReadFull(r, line) - if n == 0 || err == io.EOF { - break + if err != nil && err != io.EOF && err != io.ErrUnexpectedEOF { + return err + } + if n == 0 { + return nil } // Line offset @@ -88,5 +91,4 @@ func XXD(r io.Reader, w io.Writer) error { w.Write(newline) } - return nil }