aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/base32
diff options
context:
space:
mode:
authorMark Ryan <mark.d.ryan@intel.com>2017-06-16 11:34:28 +0100
committerBrad Fitzpatrick <bradfitz@golang.org>2017-06-16 14:53:17 +0000
commit3e0c21e0335f5ec01ea13a86e1fd32ee066f369d (patch)
treecdfdf712a0ae1a02e9931e21d25b5e4805a42fcf /src/encoding/base32
parentc52aca1c761f724c3192ee0ac4f4a19754fc5948 (diff)
downloadgo-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/base32')
-rw-r--r--src/encoding/base32/base32_test.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/encoding/base32/base32_test.go b/src/encoding/base32/base32_test.go
index 12256d08ee..ee7525c997 100644
--- a/src/encoding/base32/base32_test.go
+++ b/src/encoding/base32/base32_test.go
@@ -284,11 +284,15 @@ func TestDecoderBuffering(t *testing.T) {
decoder := NewDecoder(StdEncoding, 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)
}
}