about summary refs log tree commit diff
path: root/library/std/src/sys/net/connection/socket/unix.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-02-23 08:06:25 +0000
committerbors <bors@rust-lang.org>2025-02-23 08:06:25 +0000
commit1805b3348341e0918912ab61cb1dffad41648d23 (patch)
treede386957c473de14144f4871298ec81b38ad5bab /library/std/src/sys/net/connection/socket/unix.rs
parentbb2cc59a2172d6e35c89b409a4e6b5058d9039d7 (diff)
parentd41520052e7cd2305097af1ed0be1741ff899d7b (diff)
downloadrust-1805b3348341e0918912ab61cb1dffad41648d23.tar.gz
rust-1805b3348341e0918912ab61cb1dffad41648d23.zip
Auto merge of #137466 - jhpratt:rollup-spyi02y, r=jhpratt
Rollup of 9 pull requests

Successful merges:

 - #135354 ([Debuginfo] Add MSVC Synthetic and Summary providers to LLDB)
 - #136826 (Replace mem::zeroed with mem::MaybeUninit::uninit for large struct in Unix)
 - #137194 (More const {} init in thread_local)
 - #137334 (Greatly simplify lifetime captures in edition 2024)
 - #137382 (bootstrap: add doc for vendor build step)
 - #137423 (Improve a bit HIR pretty printer)
 - #137435 (Fix "missing match arm body" suggestion involving `!`)
 - #137448 (Fix bugs due to unhandled `ControlFlow` in compiler)
 - #137458 (Fix missing self subst when rendering `impl Fn*<T>` with no output type)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/sys/net/connection/socket/unix.rs')
-rw-r--r--library/std/src/sys/net/connection/socket/unix.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/library/std/src/sys/net/connection/socket/unix.rs b/library/std/src/sys/net/connection/socket/unix.rs
index 34ab26bc117..29fb47ddca3 100644
--- a/library/std/src/sys/net/connection/socket/unix.rs
+++ b/library/std/src/sys/net/connection/socket/unix.rs
@@ -322,7 +322,10 @@ impl Socket {
         buf: &mut [u8],
         flags: c_int,
     ) -> io::Result<(usize, SocketAddr)> {
-        let mut storage: libc::sockaddr_storage = unsafe { mem::zeroed() };
+        // The `recvfrom` function will fill in the storage with the address,
+        // so we don't need to zero it here.
+        // reference: https://linux.die.net/man/2/recvfrom
+        let mut storage: mem::MaybeUninit<libc::sockaddr_storage> = mem::MaybeUninit::uninit();
         let mut addrlen = mem::size_of_val(&storage) as libc::socklen_t;
 
         let n = cvt(unsafe {
@@ -335,7 +338,7 @@ impl Socket {
                 &mut addrlen,
             )
         })?;
-        Ok((n as usize, unsafe { socket_addr_from_c(&storage, addrlen as usize)? }))
+        Ok((n as usize, unsafe { socket_addr_from_c(storage.as_ptr(), addrlen as usize)? }))
     }
 
     pub fn recv_from(&self, buf: &mut [u8]) -> io::Result<(usize, SocketAddr)> {