diff options
Diffstat (limited to 'src/encoding/binary')
| -rw-r--r-- | src/encoding/binary/varint.go | 6 | ||||
| -rw-r--r-- | src/encoding/binary/varint_test.go | 6 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/encoding/binary/varint.go b/src/encoding/binary/varint.go index 18e1ff1511..7b14fb2b63 100644 --- a/src/encoding/binary/varint.go +++ b/src/encoding/binary/varint.go @@ -123,7 +123,7 @@ func Varint(buf []byte) (int64, int) { return x, n } -var overflow = errors.New("binary: varint overflows a 64-bit integer") +var errOverflow = errors.New("binary: varint overflows a 64-bit integer") // ReadUvarint reads an encoded unsigned integer from r and returns it as a uint64. // The error is EOF only if no bytes were read. @@ -142,14 +142,14 @@ func ReadUvarint(r io.ByteReader) (uint64, error) { } if b < 0x80 { if i == MaxVarintLen64-1 && b > 1 { - return x, overflow + return x, errOverflow } return x | uint64(b)<<s, nil } x |= uint64(b&0x7f) << s s += 7 } - return x, overflow + return x, errOverflow } // ReadVarint reads an encoded signed integer from r and returns it as an int64. diff --git a/src/encoding/binary/varint_test.go b/src/encoding/binary/varint_test.go index a3caea8a43..5c3ea318c3 100644 --- a/src/encoding/binary/varint_test.go +++ b/src/encoding/binary/varint_test.go @@ -212,9 +212,9 @@ func testOverflow(t *testing.T, buf []byte, x0 uint64, n0 int, err0 error) { } func TestOverflow(t *testing.T) { - testOverflow(t, []byte{0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x2}, 0, -10, overflow) - testOverflow(t, []byte{0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x1, 0, 0}, 0, -11, overflow) - testOverflow(t, []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, 1<<64-1, -11, overflow) // 11 bytes, should overflow + testOverflow(t, []byte{0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x2}, 0, -10, errOverflow) + testOverflow(t, []byte{0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x1, 0, 0}, 0, -11, errOverflow) + testOverflow(t, []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, 1<<64-1, -11, errOverflow) // 11 bytes, should overflow } func TestNonCanonicalZero(t *testing.T) { |
