mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
bytes: fix panic in bytes.Buffer.Peek
This change fixed the overlooked offset in bytes.Buffer.Peek.
Otherwise, it will either return wrong result or panic with
"runtime error: slice bounds out of range".
Change-Id: Ic42fd8a27fb9703c51430f298933b91cf0d45451
GitHub-Last-Rev: fb97ebc3b1
GitHub-Pull-Request: golang/go#76165
Reviewed-on: https://go-review.googlesource.com/c/go/+/717640
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
This commit is contained in:
parent
0a569528ea
commit
b57962b7c7
2 changed files with 13 additions and 7 deletions
|
|
@ -86,7 +86,7 @@ func (b *Buffer) Peek(n int) ([]byte, error) {
|
|||
if b.Len() < n {
|
||||
return b.buf[b.off:], io.EOF
|
||||
}
|
||||
return b.buf[b.off:n], nil
|
||||
return b.buf[b.off : b.off+n], nil
|
||||
}
|
||||
|
||||
// empty reports whether the unread portion of the buffer is empty.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue