diff --git a/src/lib.rs b/src/lib.rs index afbe2d3..b850698 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -117,7 +117,7 @@ impl Vechonk { pub fn push(&mut self, element: Box) { let elem_size = mem::size_of_val(element.as_ref()); - let elem_align = mem::align_of_val(&element); + let elem_align = mem::align_of_val(element.as_ref()); let elem_ptr = Box::into_raw(element); let meta = ptr::metadata(elem_ptr); @@ -155,6 +155,7 @@ impl Vechonk { // SAFETY: `elem_ptr` comes from `Box`, and is therefore valid to read from for the size // We have made sure above that we have more than `elem_size` bytes free // The two allocations cannot overlap, since the `Box` owned its contents, and so do we + // `dest_ptr` has been aligned above unsafe { ptr::copy_nonoverlapping::(elem_ptr as _, dest_ptr, elem_size); } diff --git a/src/test.rs b/src/test.rs index 2490ac2..9448bb3 100644 --- a/src/test.rs +++ b/src/test.rs @@ -133,8 +133,8 @@ fn push_alignment() { let mut chonk = Vechonk::::with_capacity(4096); - chonk.push(Box::new(0_u8)); chonk.push(Box::new(BigAlign(5))); + chonk.push(Box::new(0_u8)); chonk.push(Box::new(1_u64)); let _ = chonk[0];