From 02dab5a3e79a48c77d28c9aa6dcfea173584933b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 20 Mar 2014 18:53:30 -0700 Subject: [PATCH] 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. --- src/librand/reader.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/librand/reader.rs b/src/librand/reader.rs index 744930e028cb9..9e7e38d27239a 100644 --- a/src/librand/reader.rs +++ b/src/librand/reader.rs @@ -60,10 +60,8 @@ impl Rng for ReaderRng { } fn fill_bytes(&mut self, v: &mut [u8]) { if v.len() == 0 { return } - match self.reader.read(v) { - Ok(n) if n == v.len() => return, - Ok(n) => fail!("ReaderRng.fill_bytes could not fill buffer: \ - read {} out of {} bytes.", n, v.len()), + match self.reader.fill(v) { + Ok(()) => {} Err(e) => fail!("ReaderRng.fill_bytes error: {}", e) } }