Skip to content

Commit afe2036

Browse files
bors[bot]CAD97
andauthored
Merge #45
45: Don't use slice::from_raw_parts for uninitialized memory r=CAD97 a=CAD97 This is a very annoying incorrect usage of `slice::from_raw_parts` rather than `slice_from_raw_parts`. This is a freshly allocated pointer, and specifically a pointer to uninitialized memory. So (when available) it is sound to use `ptr::slice_from_raw_parts_mut` and _unsound_ to use `slice::from_raw_parts_mut`. Yay for yanking another version. bors: r+ Co-authored-by: CAD97 <[email protected]>
2 parents 64c7467 + bab5fb0 commit afe2036

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

crates/slice-dst/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ use {
9999
alloc::{alloc, dealloc, handle_alloc_error},
100100
boxed::Box,
101101
},
102-
core::{alloc::Layout, mem::ManuallyDrop, ptr, slice},
102+
core::{alloc::Layout, mem::ManuallyDrop, ptr},
103103
};
104104

105105
/// A custom slice-based dynamically sized type.
@@ -173,7 +173,7 @@ where
173173
ptr::NonNull::new(alloc(layout) as *mut ())
174174
}
175175
.unwrap_or_else(|| handle_alloc_error(layout));
176-
let ptr = ptr::NonNull::new_unchecked(slice::from_raw_parts_mut::<()>(ptr.as_ptr(), len));
176+
let ptr = ptr::NonNull::new_unchecked(slice_from_raw_parts(ptr.as_ptr(), len));
177177
S::retype(ptr)
178178
}
179179
}

0 commit comments

Comments
 (0)