bytes: fix bugs in buffer.ReadBytes

Fixes #1498.

R=golang-dev, mattn, r, rsc
CC=golang-dev
https://golang.org/cl/4140041
This commit is contained in:
Evan Shaw 2011-02-11 12:39:18 -05:00 committed by Russ Cox
parent 4ee90b764e
commit bbfad5f1cc
2 changed files with 25 additions and 13 deletions

View file

@ -312,13 +312,14 @@ func (b *Buffer) UnreadByte() os.Error {
// delim.
func (b *Buffer) ReadBytes(delim byte) (line []byte, err os.Error) {
i := IndexByte(b.buf[b.off:], delim)
size := i + 1 - b.off
size := i + 1
if i < 0 {
size = len(b.buf) - b.off
err = os.EOF
}
line = make([]byte, size)
copy(line, b.buf[b.off:])
b.off += size
return
}