aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/binary/varint.go
diff options
context:
space:
mode:
authorKatie Hockman <katie@golang.org>2020-08-06 13:10:42 -0400
committerKatie Hockman <katie@golang.org>2020-08-06 13:10:52 -0400
commit2bc8d90fa21e9547aeb0f0ae775107dc8e05dc0a (patch)
treeefd528fea33c766e196a0d88c5e6533e7003f832 /src/encoding/binary/varint.go
parent5ebdfd905d8f2d70601aa11212d579fa60abdb0f (diff)
parente71b61180aa19a60c23b3b7e3f6586726ebe4fd1 (diff)
downloadgo-release-branch.go1.13.tar.gz
go-release-branch.go1.13.zip
[release-branch.go1.13] all: merge release-branch.go1.13-security into release-branch.go1.13release-branch.go1.13
Change-Id: Ib8a4c5f58de71145525ba23562bf8a0c35b60c9c
Diffstat (limited to 'src/encoding/binary/varint.go')
-rw-r--r--src/encoding/binary/varint.go5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/encoding/binary/varint.go b/src/encoding/binary/varint.go
index bcb8ac9a45..38af61075c 100644
--- a/src/encoding/binary/varint.go
+++ b/src/encoding/binary/varint.go
@@ -106,13 +106,13 @@ var overflow = errors.New("binary: varint overflows a 64-bit integer")
func ReadUvarint(r io.ByteReader) (uint64, error) {
var x uint64
var s uint
- for i := 0; ; i++ {
+ for i := 0; i < MaxVarintLen64; i++ {
b, err := r.ReadByte()
if err != nil {
return x, err
}
if b < 0x80 {
- if i > 9 || i == 9 && b > 1 {
+ if i == 9 && b > 1 {
return x, overflow
}
return x | uint64(b)<<s, nil
@@ -120,6 +120,7 @@ func ReadUvarint(r io.ByteReader) (uint64, error) {
x |= uint64(b&0x7f) << s
s += 7
}
+ return x, overflow
}
// ReadVarint reads an encoded signed integer from r and returns it as an int64.