diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-08-07 15:17:35 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-08-07 17:22:33 -0700 |
commit | 10c8507372f3e1c09df0bfe6449c126dee5075de (patch) | |
tree | 27c7db25f91db33c83f56cc75621e61fbf21d921 /libgo/go/encoding/binary/varint_test.go | |
parent | a72e938d710fa4b6c8eb89c4daab68e320fa97df (diff) | |
download | gcc-10c8507372f3e1c09df0bfe6449c126dee5075de.zip gcc-10c8507372f3e1c09df0bfe6449c126dee5075de.tar.gz gcc-10c8507372f3e1c09df0bfe6449c126dee5075de.tar.bz2 |
libgo: update to Go1.15rc2 release
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/247517
Diffstat (limited to 'libgo/go/encoding/binary/varint_test.go')
-rw-r--r-- | libgo/go/encoding/binary/varint_test.go | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/libgo/go/encoding/binary/varint_test.go b/libgo/go/encoding/binary/varint_test.go index ca411ec..6ef4c99 100644 --- a/libgo/go/encoding/binary/varint_test.go +++ b/libgo/go/encoding/binary/varint_test.go @@ -121,21 +121,27 @@ func TestBufferTooSmall(t *testing.T) { } } -func testOverflow(t *testing.T, buf []byte, n0 int, err0 error) { +func testOverflow(t *testing.T, buf []byte, x0 uint64, n0 int, err0 error) { x, n := Uvarint(buf) if x != 0 || n != n0 { t.Errorf("Uvarint(%v): got x = %d, n = %d; want 0, %d", buf, x, n, n0) } - x, err := ReadUvarint(bytes.NewReader(buf)) - if x != 0 || err != err0 { - t.Errorf("ReadUvarint(%v): got x = %d, err = %s; want 0, %s", buf, x, err, err0) + r := bytes.NewReader(buf) + len := r.Len() + x, err := ReadUvarint(r) + if x != x0 || err != err0 { + t.Errorf("ReadUvarint(%v): got x = %d, err = %s; want %d, %s", buf, x, err, x0, err0) + } + if read := len - r.Len(); read > MaxVarintLen64 { + t.Errorf("ReadUvarint(%v): read more than MaxVarintLen64 bytes, got %d", buf, read) } } func TestOverflow(t *testing.T) { - testOverflow(t, []byte{0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x2}, -10, overflow) - testOverflow(t, []byte{0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x1, 0, 0}, -13, overflow) + 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, -13, overflow) + testOverflow(t, []byte{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, 1<<64-1, 0, overflow) // 11 bytes, should overflow } func TestNonCanonicalZero(t *testing.T) { |