Skip to content

Commit 02dab5a

Browse files
committed
rand: Use fill() instead of read()
It's possible for a reader to have a short read, and there's no reason the task should fail in this scenario. By using fill(), this has a stronger guarantee that the buffer will get filled with data.
1 parent 5560383 commit 02dab5a

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/librand/reader.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,8 @@ impl<R: Reader> Rng for ReaderRng<R> {
6060
}
6161
fn fill_bytes(&mut self, v: &mut [u8]) {
6262
if v.len() == 0 { return }
63-
match self.reader.read(v) {
64-
Ok(n) if n == v.len() => return,
65-
Ok(n) => fail!("ReaderRng.fill_bytes could not fill buffer: \
66-
read {} out of {} bytes.", n, v.len()),
63+
match self.reader.fill(v) {
64+
Ok(()) => {}
6765
Err(e) => fail!("ReaderRng.fill_bytes error: {}", e)
6866
}
6967
}

0 commit comments

Comments
 (0)