Closed
Description
The example code for std::rand::Rng::fill_bytes
fails due to a stack overflow:
use std::rand::{task_rng, Rng};
fn main() {
let mut v = [0u8, .. 13579];
task_rng().fill_bytes(v);
println!("{:?}", v);
}
This is due to infinite recursion in the ReseedingRng
trait (src/libstd/rand/reseeding.rs:72):
fn fill_bytes(&mut self, dest: &mut [u8]) {
self.reseed_if_necessary();
self.bytes_generated += dest.len();
self.fill_bytes(dest)
}
}
self.fill_bytes(dest)
should be self.rng.fill_bytes(dest)
-- changing the line to that fixes the issue.
Metadata
Metadata
Assignees
Labels
No labels
Activity
alexcrichton commentedon Oct 31, 2013
Oh that's not good! cc @huonw so he's aware, but if you would like to fix it (looks like the fix you have is legitimate), feel free to make the change, add some tests, and open a pull request!
huonw commentedon Oct 31, 2013
Oops! Second time I've done this with the RNG stuff! 😦
@telotortium tell me if you're not going to fix it, so I can whip up a patch.
telotortium commentedon Oct 31, 2013
I'll fix it in an hour or two.
fill_bytes()
#10213auto merge of #10213 : telotortium/rust/rand-fill_bytes-stack-overflo…
new lint: `char_indices_as_byte_indices` (rust-lang#13435)