arbitrary/foreign/alloc/ffi/
c_str.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use {
    crate::{Arbitrary, Result, Unstructured},
    std::ffi::CString,
};

impl<'a> Arbitrary<'a> for CString {
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
        <Vec<u8> as Arbitrary>::arbitrary(u).map(|mut x| {
            x.retain(|&c| c != 0);
            // SAFETY: all zero bytes have been removed
            unsafe { Self::from_vec_unchecked(x) }
        })
    }

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