diff options
| author | LinkTed <LinkTed@users.noreply.github.com> | 2020-08-25 18:09:35 +0200 |
|---|---|---|
| committer | LinkTed <LinkTed@users.noreply.github.com> | 2020-10-10 15:19:11 +0200 |
| commit | 8784ffbb4e45c6081369805fccd34b77f3ef8ec1 (patch) | |
| tree | 6e93f016783686f19e2571f44a31f81105593156 /library | |
| parent | 8783b06bd2c5165cbb356d06bbaf943fae6937a2 (diff) | |
| download | rust-8784ffbb4e45c6081369805fccd34b77f3ef8ec1.tar.gz rust-8784ffbb4e45c6081369805fccd34b77f3ef8ec1.zip | |
Using `read_unaligned` instead of `memcpy`.
Diffstat (limited to 'library')
| -rw-r--r-- | library/std/src/sys/unix/ext/net/ancillary.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/library/std/src/sys/unix/ext/net/ancillary.rs b/library/std/src/sys/unix/ext/net/ancillary.rs index 03fd288b870..039cdd8ff91 100644 --- a/library/std/src/sys/unix/ext/net/ancillary.rs +++ b/library/std/src/sys/unix/ext/net/ancillary.rs @@ -4,7 +4,7 @@ use crate::marker::PhantomData; use crate::mem::{size_of, zeroed}; use crate::os::unix::io::RawFd; use crate::path::Path; -use crate::ptr::null_mut; +use crate::ptr::{null_mut, read_unaligned}; use crate::slice::from_raw_parts; use crate::sys::unix::ext::net::addr::{sockaddr_un, SocketAddr}; use crate::sys::unix::net::Socket; @@ -131,16 +131,14 @@ impl<'a, T> Iterator for AncillaryDataIter<'a, T> { type Item = T; fn next(&mut self) -> Option<T> { - unsafe { - let mut unit = zeroed(); - if size_of::<T>() <= self.data.len() { - let unit_ptr: *mut T = &mut unit; - libc::memcpy(unit_ptr.cast(), self.data.as_ptr().cast(), size_of::<T>()); + if size_of::<T>() <= self.data.len() { + unsafe { + let unit = read_unaligned(self.data.as_ptr().cast()); self.data = &self.data[size_of::<T>()..]; Some(unit) - } else { - None } + } else { + None } } } |
