diff --git a/src/send-and-sync.md b/src/send-and-sync.md index fd1bb94..33860ef 100644 --- a/src/send-and-sync.md +++ b/src/send-and-sync.md @@ -93,10 +93,11 @@ struct Carton(NonNull); impl Carton { pub fn new(value: T) -> Self { // Allocate enough memory on the heap to store one T. - let memptr = &mut null_mut() as *mut *mut T; + assert_ne!(size_of::(), 0, "Zero-sized types are out of the scope of this example); + let memptr: *mut c_void = ptr::null_mut(); unsafe { let ret = libc::posix_memalign( - memptr as *mut *mut c_void, + &mut memptr, align_of::(), size_of::() ); @@ -107,7 +108,7 @@ impl Carton { let mut ptr = unsafe { // Safety: memptr is dereferenceable because we created it from a // reference and have exclusive access. - NonNull::new(*memptr) + NonNull::new(memptr.cast::()) .expect("Guaranteed non-null if posix_memalign returns 0") };