Skip to content

Commit

Permalink
rand: Use fill() instead of read()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alexcrichton committed Mar 22, 2014
1 parent 5560383 commit 02dab5a
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/librand/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ impl<R: Reader> Rng for ReaderRng<R> {
}
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)
}
}
Expand Down

5 comments on commit 02dab5a

@bors
Copy link
Contributor

@bors bors commented on 02dab5a Mar 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from huonw
at alexcrichton@02dab5a

@bors
Copy link
Contributor

@bors bors commented on 02dab5a Mar 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/io-fill = 02dab5a into auto

@bors
Copy link
Contributor

@bors bors commented on 02dab5a Mar 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/io-fill = 02dab5a merged ok, testing candidate = e06348e

@bors
Copy link
Contributor

@bors bors commented on 02dab5a Mar 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 02dab5a Mar 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = e06348e

Please sign in to comment.