aboutsummaryrefslogtreecommitdiff
path: root/src/bytes/buffer.go
diff options
context:
space:
mode:
authorAaron Chen <aaronchen.lisp@gmail.com>2025-11-13 01:43:03 +0000
committerGopher Robot <gobot@golang.org>2025-11-14 11:01:17 -0800
commitb57962b7c7de2b70fa943e66cd26b2cce631b7f8 (patch)
tree085af29ace6ebf331c8eab02d2d122f9268b9a33 /src/bytes/buffer.go
parent0a569528ea355099af864f7612c3fa1973df30e4 (diff)
downloadgo-b57962b7c7de2b70fa943e66cd26b2cce631b7f8.tar.xz
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: fb97ebc3b188959835706626f66898d6306c16fb 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>
Diffstat (limited to 'src/bytes/buffer.go')
-rw-r--r--src/bytes/buffer.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/bytes/buffer.go b/src/bytes/buffer.go
index 3eb5b350c3..6cb4d6a8f6 100644
--- a/src/bytes/buffer.go
+++ b/src/bytes/buffer.go
@@ -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.