From b8c3d928dec8ac37c66850071345de2629abb503 Mon Sep 17 00:00:00 2001 From: FarzadMohtasham Date: Mon, 28 Apr 2025 03:48:09 +0330 Subject: [PATCH 1/2] Updated Rand dependency to v0.9.1 --- Cargo.toml | 2 +- tests/header_map_fuzz.rs | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 29ee6c1c..97205378 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,7 +43,7 @@ itoa = "1" [dev-dependencies] quickcheck = "1" -rand = "0.8.0" +rand = "0.9.1" serde = "1.0" serde_json = "1.0" doc-comment = "0.3" diff --git a/tests/header_map_fuzz.rs b/tests/header_map_fuzz.rs index 40db0494..a6b2208f 100644 --- a/tests/header_map_fuzz.rs +++ b/tests/header_map_fuzz.rs @@ -2,8 +2,9 @@ use http::header::*; use http::*; use quickcheck::{Arbitrary, Gen, QuickCheck, TestResult}; +use rand::prelude::IndexedRandom; use rand::rngs::StdRng; -use rand::seq::SliceRandom; +// use rand::seq::SliceRandom; use rand::{Rng, SeedableRng}; use std::collections::HashMap; @@ -76,12 +77,12 @@ impl Fuzz { let mut steps = vec![]; let mut expect = AltMap::default(); - let num = rng.gen_range(5..500); + let num = rng.random_range(5..500); let weight = Weight { - insert: rng.gen_range(1..10), - remove: rng.gen_range(1..10), - append: rng.gen_range(1..10), + insert: rng.random_range(1..10), + remove: rng.random_range(1..10), + append: rng.random_range(1..10), }; while steps.len() < num { @@ -112,7 +113,7 @@ impl Fuzz { impl Arbitrary for Fuzz { fn arbitrary(_: &mut Gen) -> Self { - Self::new(rand::thread_rng().gen()) + Self::new(rand::rng().random()) } } @@ -130,7 +131,7 @@ impl AltMap { fn gen_action(&mut self, weight: &Weight, rng: &mut StdRng) -> Action { let sum = weight.insert + weight.remove + weight.append; - let mut num = rng.gen_range(0..sum); + let mut num = rng.random_range(0..sum); if num < weight.insert { return self.gen_insert(rng); @@ -180,7 +181,7 @@ impl AltMap { /// Negative numbers weigh finding an existing header higher fn gen_name(&self, weight: i32, rng: &mut StdRng) -> HeaderName { - let mut existing = rng.gen_ratio(1, weight.abs() as u32); + let mut existing = rng.random_ratio(1, weight.abs() as u32); if weight < 0 { existing = !existing; @@ -202,7 +203,7 @@ impl AltMap { if self.map.is_empty() { None } else { - let n = rng.gen_range(0..self.map.len()); + let n = rng.random_range(0..self.map.len()); self.map.keys().nth(n).map(Clone::clone) } } @@ -337,7 +338,7 @@ fn gen_header_name(g: &mut StdRng) -> HeaderName { header::X_XSS_PROTECTION, ]; - if g.gen_ratio(1, 2) { + if g.random_ratio(1, 2) { STANDARD_HEADERS.choose(g).unwrap().clone() } else { let value = gen_string(g, 1, 25); From 56ea624814a47f9f2699d1486d0ba84fcc91e427 Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Mon, 28 Apr 2025 08:47:02 -0400 Subject: [PATCH 2/2] Update tests/header_map_fuzz.rs --- tests/header_map_fuzz.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/header_map_fuzz.rs b/tests/header_map_fuzz.rs index a6b2208f..e6a43e8d 100644 --- a/tests/header_map_fuzz.rs +++ b/tests/header_map_fuzz.rs @@ -4,7 +4,6 @@ use http::*; use quickcheck::{Arbitrary, Gen, QuickCheck, TestResult}; use rand::prelude::IndexedRandom; use rand::rngs::StdRng; -// use rand::seq::SliceRandom; use rand::{Rng, SeedableRng}; use std::collections::HashMap;