FAQ
https://codereview.appspot.com/6565056/diff/5001/src/pkg/bufio/bufio.go
File src/pkg/bufio/bufio.go (right):

https://codereview.appspot.com/6565056/diff/5001/src/pkg/bufio/bufio.go#newcode582
src/pkg/bufio/bufio.go:582: for m, err = b.readBuf(r); m > 0 && err ==
nil; m, err = b.readBuf(r) {
This isn't right. "godoc io Reader" says that it's valid for r.Read to
return m > 0 and err == io.EOF at the end of file, and those m bytes
will be ignored by this loop. I think that you want something like

for {
m, err := r.Read(b.buf[b.n:])
b.n += m
n += m
// r.Read can return m > 0 && err != nil, such as at end of file.
// We need to flush those m bytes before returning.
if err1 := b.Flush(); err1 != nil {
return n, err1
}
if err != nil {
if err == io.EOF {
err = nil
}
return n, err
}
}
panic("unreachable")

A test of this (m > 0 && err != nil) code path would be good.

https://codereview.appspot.com/6565056/diff/5001/src/pkg/bufio/bufio_test.go
File src/pkg/bufio/bufio_test.go (right):

https://codereview.appspot.com/6565056/diff/5001/src/pkg/bufio/bufio_test.go#newcode778
src/pkg/bufio/bufio_test.go:778: }
Add a blank line after this.

https://codereview.appspot.com/6565056/

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedSep 28, '12 at 4:49a
activeSep 28, '12 at 6:15a
posts4
users2
websitegolang.org

2 users in discussion

Mchaten: 3 posts Nigeltao: 1 post

People

Translate

site design / logo © 2022 Grokbase