diff options
author | Mark Ryan <mark.d.ryan@intel.com> | 2017-06-16 11:34:28 +0100 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2017-06-16 14:53:17 +0000 |
commit | 3e0c21e0335f5ec01ea13a86e1fd32ee066f369d (patch) | |
tree | cdfdf712a0ae1a02e9931e21d25b5e4805a42fcf /src/encoding/ascii85 | |
parent | c52aca1c761f724c3192ee0ac4f4a19754fc5948 (diff) | |
download | go-3e0c21e0335f5ec01ea13a86e1fd32ee066f369d.tar.gz go-3e0c21e0335f5ec01ea13a86e1fd32ee066f369d.zip |
encoding: fix endless loop in TestDecoderBuffering
The ascii85, base32 and base64 packages all contain a test called
TestDecoderBuffering. Each of these tests contain a loop that ignores
the error returned from the Read method of their decoders. The result
being that the tests loop for ever if the decoders actually return an
error. This commit fixes the issue by terminating the loops if an error
occurs and failing the tests with a suitable error message.
Change-Id: Idb385673cf9f3f6f8befe4288b4be366ab0985fd
Reviewed-on: https://go-review.googlesource.com/46010
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/encoding/ascii85')
-rw-r--r-- | src/encoding/ascii85/ascii85_test.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/encoding/ascii85/ascii85_test.go b/src/encoding/ascii85/ascii85_test.go index ba85b64156..b8be960863 100644 --- a/src/encoding/ascii85/ascii85_test.go +++ b/src/encoding/ascii85/ascii85_test.go @@ -135,11 +135,15 @@ func TestDecoderBuffering(t *testing.T) { decoder := NewDecoder(strings.NewReader(bigtest.encoded)) buf := make([]byte, len(bigtest.decoded)+12) var total int - for total = 0; total < len(bigtest.decoded); { - n, err := decoder.Read(buf[total : total+bs]) - testEqual(t, "Read from %q at pos %d = %d, %v, want _, %v", bigtest.encoded, total, n, err, error(nil)) + var n int + var err error + for total = 0; total < len(bigtest.decoded) && err == nil; { + n, err = decoder.Read(buf[total : total+bs]) total += n } + if err != nil && err != io.EOF { + t.Errorf("Read from %q at pos %d = %d, unexpected error %v", bigtest.encoded, total, n, err) + } testEqual(t, "Decoding/%d of %q = %q, want %q", bs, bigtest.encoded, string(buf[0:total]), bigtest.decoded) } } |