udp: document and shrink some unsafe blocks (#4655)

This documents why it is safe to convert `bytes::UninitSlice` to `&mut
[MaybeUninit<u8>]`, and shrinks one of the unsafe blocks to make these
functions easier to audit.
This commit is contained in:
Erick Tryzelaar
2022-05-05 19:48:39 +00:00
committed by GitHub
parent 2a305d2423
commit c5ff797dcf
2 changed files with 12 additions and 5 deletions
+3
View File
@@ -115,6 +115,9 @@ mod util {
let n = {
let dst = buf.chunk_mut();
// Safety: `chunk_mut()` returns a `&mut UninitSlice`, and `UninitSlice` is a
// transparent wrapper around `[MaybeUninit<u8>]`.
let dst = unsafe { &mut *(dst as *mut _ as *mut [MaybeUninit<u8>]) };
let mut buf = ReadBuf::uninit(dst);
let ptr = buf.filled().as_ptr();