remove some UB

This commit is contained in:
Folkert 2023-04-06 16:10:31 +02:00
parent 92c2931678
commit f63460eb69
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
2 changed files with 2 additions and 1 deletions

View file

@ -18,6 +18,7 @@ pub extern "C" fn rust_main() -> i32 {
// Verify that it has all the expected traits.
assert!(tag_union == tag_union); // PartialEq
assert!(tag_union.clone() == tag_union.clone()); // Clone
assert!(tag_union.partial_cmp(&tag_union) == Some(Ordering::Equal)); // PartialOrd

View file

@ -33,7 +33,7 @@ impl<T> RocBox<T> {
let contents = unsafe {
let contents_ptr = ptr.cast::<u8>().add(alignment).cast::<T>();
*contents_ptr = contents;
core::ptr::write(contents_ptr, contents);
// We already verified that the original alloc pointer was non-null,
// and this one is the alloc pointer with `alignment` bytes added to it,