diff --git a/src/io/cmsg.rs b/src/io/cmsg.rs index 28acca6..293b69d 100644 --- a/src/io/cmsg.rs +++ b/src/io/cmsg.rs @@ -14,11 +14,10 @@ pub const fn capacity() -> usize { pub fn buffer() -> Vec { let capacity = capacity::(); - let mut buf = Vec::with_capacity(capacity); unsafe { - buf.set_len(capacity); + let data = std::alloc::alloc(std::alloc::Layout::array::(capacity).unwrap()); + Vec::from_raw_parts(data as *mut u8, capacity, capacity) } - buf } pub struct RawCmsgIterator<'a> { diff --git a/src/tools.rs b/src/tools.rs index 01a32b5..44cd943 100644 --- a/src/tools.rs +++ b/src/tools.rs @@ -54,9 +54,8 @@ pub mod vec { /// This is generally safe to call, but the contents of the vector are undefined. #[inline] pub unsafe fn uninitialized(len: usize) -> Vec { - let mut out = Vec::with_capacity(len); - out.set_len(len); - out + let data = std::alloc::alloc(std::alloc::Layout::array::(len).unwrap()); + Vec::from_raw_parts(data as *mut u8, len, len) } }