mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
4ee90b764e
commit
bbfad5f1cc
2 changed files with 25 additions and 13 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue