• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use {
2     crate::{Arbitrary, Result, Unstructured},
3     std::ffi::CString,
4 };
5 
6 impl<'a> Arbitrary<'a> for CString {
arbitrary(u: &mut Unstructured<'a>) -> Result<Self>7     fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
8         <Vec<u8> as Arbitrary>::arbitrary(u).map(|mut x| {
9             x.retain(|&c| c != 0);
10             // SAFETY: all zero bytes have been removed
11             unsafe { Self::from_vec_unchecked(x) }
12         })
13     }
14 
15     #[inline]
size_hint(depth: usize) -> (usize, Option<usize>)16     fn size_hint(depth: usize) -> (usize, Option<usize>) {
17         <Vec<u8> as Arbitrary>::size_hint(depth)
18     }
19 }
20