Skip to content

Commit 2a0077f

Browse files
authored
Merge pull request #161 from 00xc/main
Minor improvements
2 parents 66e75c5 + e5f3d2a commit 2a0077f

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/lib.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,7 @@ macro_rules! impl_arbitrary_for_integers {
309309
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
310310
let mut buf = [0; mem::size_of::<$ty>()];
311311
u.fill_buffer(&mut buf)?;
312-
let mut x: $unsigned = 0;
313-
for i in 0..mem::size_of::<$ty>() {
314-
x |= buf[i] as $unsigned << (i * 8);
315-
}
316-
Ok(x as $ty)
312+
Ok(Self::from_le_bytes(buf))
317313
}
318314

319315
#[inline]
@@ -889,7 +885,8 @@ impl<'a> Arbitrary<'a> for CString {
889885
fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
890886
<Vec<u8> as Arbitrary>::arbitrary(u).map(|mut x| {
891887
x.retain(|&c| c != 0);
892-
Self::new(x).unwrap()
888+
// SAFETY: all zero bytes have been removed
889+
unsafe { Self::from_vec_unchecked(x) }
893890
})
894891
}
895892

0 commit comments

Comments
 (0)