Skip to content

std::rand::reseeding: infinite recursion in fill_bytes() #10202

Closed
@telotortium

Description

@telotortium

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions