read the actual number of bytes according to the initial size.

Signed-off-by: yuzou <zouyu7@huawei.com>
This commit is contained in:
yuzou 2016-02-04 16:14:35 +08:00
parent c4b79bda8a
commit 95b9c7281b

View file

@ -1184,7 +1184,11 @@ func (rr *randReader) Read(p []byte) (n int, err error) {
rr.m.Lock()
defer rr.m.Unlock()
n = copy(p, randomContents(int64(len(p))))
toread := int64(len(p))
if toread > rr.r {
toread = rr.r
}
n = copy(p, randomContents(toread))
rr.r -= int64(n)
if rr.r <= 0 {