Skip to content

Commit 6c8e616

Browse files
committed
fixup
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent 9d278dc commit 6c8e616

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

fuzz/src/fsst_like.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ use crate::error::VortexFuzzResult;
3333
static SESSION: LazyLock<VortexSession> =
3434
LazyLock::new(|| VortexSession::empty().with::<ArraySession>());
3535

36+
/// A random string from a small alphabet (`a..=h`) with bounded length.
37+
#[derive(Debug)]
38+
struct SmallAlphabetString {
39+
max_len: usize,
40+
}
41+
42+
impl SmallAlphabetString {
43+
fn generate(&self, u: &mut Unstructured<'_>) -> arbitrary::Result<String> {
44+
let len: usize = u.int_in_range(0..=self.max_len)?;
45+
Ok((0..len)
46+
.map(|_| u.int_in_range(b'a'..=b'h').expect("cannot make char") as char)
47+
.collect())
48+
}
49+
}
50+
3651
/// Fuzz input: a set of strings and a LIKE pattern.
3752
#[derive(Debug)]
3853
pub struct FuzzFsstLike {
@@ -43,34 +58,19 @@ pub struct FuzzFsstLike {
4358

4459
impl<'a> Arbitrary<'a> for FuzzFsstLike {
4560
fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<Self> {
46-
// Generate 1-200 strings, each 0-100 bytes from a small alphabet
47-
// to increase FSST symbol reuse and substring hits.
4861
let n_strings: usize = u.int_in_range(1..=200)?;
49-
let mut strings = Vec::with_capacity(n_strings);
50-
for _ in 0..n_strings {
51-
let len: usize = u.int_in_range(0..=100)?;
52-
let s: String = (0..len)
53-
.map(|_| {
54-
let b = u.int_in_range(b'a'..=b'h').unwrap_or(b'a');
55-
b as char
56-
})
57-
.collect();
58-
strings.push(s);
59-
}
62+
let str_gen = SmallAlphabetString { max_len: 512 };
63+
let strings: Vec<String> = (0..n_strings)
64+
.map(|_| str_gen.generate(u))
65+
.collect::<arbitrary::Result<_>>()?;
6066

61-
// Generate a pattern: pick a shape then fill in the literal part.
62-
let needle_len: usize = u.int_in_range(0..=30)?;
63-
let needle: String = (0..needle_len)
64-
.map(|_| {
65-
let b = u.int_in_range(b'a'..=b'h').unwrap_or(b'a');
66-
b as char
67-
})
68-
.collect();
67+
let needle = SmallAlphabetString { max_len: 254 }.generate(u)?;
6968

7069
let pattern = match u.int_in_range(0..=2)? {
7170
0 => format!("{needle}%"), // prefix
7271
1 => format!("%{needle}%"), // contains
73-
_ => format!("%{needle}"), // suffix (should fall back, still correct)
72+
2 => format!("%{needle}"), // suffix (should fall back, still correct)
73+
_ => unreachable!(""),
7474
};
7575

7676
let negated: bool = u.arbitrary()?;

0 commit comments

Comments
 (0)