Skip to content

Commit 79b5366

Browse files
authored
Fixes double bug in Send-Sync example (#401)
1 parent 2d3e6f6 commit 79b5366

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/send-and-sync.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ to the heap.
9494
use std::{
9595
mem::{align_of, size_of},
9696
ptr,
97+
cmp::max,
9798
};
9899

99100
struct Carton<T>(ptr::NonNull<T>);
@@ -105,8 +106,8 @@ impl<T> Carton<T> {
105106
let mut memptr: *mut T = ptr::null_mut();
106107
unsafe {
107108
let ret = libc::posix_memalign(
108-
(&mut memptr).cast(),
109-
align_of::<T>(),
109+
(&mut memptr as *mut *mut T).cast(),
110+
max(align_of::<T>(), size_of::<usize>()),
110111
size_of::<T>()
111112
);
112113
assert_eq!(ret, 0, "Failed to allocate or invalid alignment");

0 commit comments

Comments
 (0)