From 79b53665a7c61d171fb8c5ad0b73b371f9ee6ba7 Mon Sep 17 00:00:00 2001 From: Dmitry Mottl Date: Mon, 13 Feb 2023 10:40:24 +0200 Subject: [PATCH] Fixes double bug in Send-Sync example (#401) --- src/send-and-sync.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/send-and-sync.md b/src/send-and-sync.md index 34539da..808a5c3 100644 --- a/src/send-and-sync.md +++ b/src/send-and-sync.md @@ -94,6 +94,7 @@ to the heap. use std::{ mem::{align_of, size_of}, ptr, + cmp::max, }; struct Carton(ptr::NonNull); @@ -105,8 +106,8 @@ impl Carton { let mut memptr: *mut T = ptr::null_mut(); unsafe { let ret = libc::posix_memalign( - (&mut memptr).cast(), - align_of::(), + (&mut memptr as *mut *mut T).cast(), + max(align_of::(), size_of::()), size_of::() ); assert_eq!(ret, 0, "Failed to allocate or invalid alignment");