mirror of
https://github.com/golang/go
synced 2024-11-23 20:40:07 -07:00
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>
This commit is contained in:
parent
c52aca1c76
commit
3e0c21e033
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -189,11 +189,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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user