Skip to content

Commit

Permalink
Revert "reader: move error check in validate"
Browse files Browse the repository at this point in the history
This reverts commit 23d7fec.

When using Read, process the returned data before looking for errors. Errors happened after the returned data, so they should be processed after the data too.

Change-Id: I17f935521b76a35db5967cdb5e9b87bd0ab8a1bb
Reviewed-on: https://go-review.googlesource.com/16103
Reviewed-by: Andrew Gerrand <adg@golang.org>
  • Loading branch information
kytrinyx authored and adg committed Oct 20, 2015
1 parent b9bdbaa commit 8640b97
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions reader/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ func Validate(r io.Reader) {
i, o := 0, 0
for ; i < 1<<20 && o < 1<<20; i++ { // test 1mb
n, err := r.Read(b)
if err != nil {
fmt.Fprintf(os.Stderr, "read error: %v\n", err)
return
}
for i, v := range b[:n] {
if v != 'A' {
fmt.Fprintf(os.Stderr, "got byte %x at offset %v, want 'A'\n", v, o+i)
return
}
}
o += n
if err != nil {
fmt.Fprintf(os.Stderr, "read error: %v\n", err)
return
}
}
if o == 0 {
fmt.Fprintf(os.Stderr, "read zero bytes after %d Read calls\n", i)
Expand Down

0 comments on commit 8640b97

Please sign in to comment.