1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix use of cap in MultiReadSeeker

Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
This commit is contained in:
Tom Wilkie 2016-11-17 18:30:35 +00:00
parent 8a6c5358af
commit 158bb9bbd5
2 changed files with 22 additions and 1 deletions

View file

@ -155,7 +155,7 @@ func (r *multiReadSeeker) Read(b []byte) (int, error) {
r.pos = &pos{0, 0}
}
bCap := int64(cap(b))
bCap := int64(len(b))
buf := bytes.NewBuffer(nil)
var rdr io.ReadSeeker

View file

@ -2,6 +2,7 @@ package ioutils
import (
"bytes"
"encoding/binary"
"fmt"
"io"
"io/ioutil"
@ -188,3 +189,23 @@ func TestMultiReadSeekerCurAfterSet(t *testing.T) {
t.Fatalf("reader size does not match, got %d, expected %d", size, mid+18)
}
}
func TestMultiReadSeekerSmallReads(t *testing.T) {
readers := []io.ReadSeeker{}
for i := 0; i < 10; i++ {
integer := make([]byte, 4, 4)
binary.BigEndian.PutUint32(integer, uint32(i))
readers = append(readers, bytes.NewReader(integer))
}
reader := MultiReadSeeker(readers...)
for i := 0; i < 10; i++ {
var integer uint32
if err := binary.Read(reader, binary.BigEndian, &integer); err != nil {
t.Fatalf("Read from NewMultiReadSeeker failed: %v", err)
}
if uint32(i) != integer {
t.Fatalf("Read wrong value from NewMultiReadSeeker: %d != %d", i, integer)
}
}
}