Skip to content

Commit

Permalink
Make usize's wire format independent of machine word size
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrmaxmeier committed May 31, 2024
1 parent ebd02e4 commit 282cc87
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,36 @@ impl_arbitrary_for_integers! {
u32;
u64;
u128;
usize;
i8;
i16;
i32;
i64;
i128;
isize;
}

// Note: We forward Arbitrary for i/usize to i/u64 in order to simplify corpus
// compatibility between 32-bit and 64-bit builds. This introduces dead space in
// 32-bit builds but keeps the input layout independent of the build platform.
impl<'a> Arbitrary<'a> for usize {
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
u.arbitrary::<u64>().map(|x| x as usize)
}

#[inline]
fn size_hint(depth: usize) -> (usize, Option<usize>) {
<u64 as Arbitrary>::size_hint(depth)
}
}

impl<'a> Arbitrary<'a> for isize {
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
u.arbitrary::<i64>().map(|x| x as isize)
}

#[inline]
fn size_hint(depth: usize) -> (usize, Option<usize>) {
<i64 as Arbitrary>::size_hint(depth)
}
}

macro_rules! impl_arbitrary_for_floats {
Expand Down

0 comments on commit 282cc87

Please sign in to comment.