From 5c79b089351c1615969bf4db276473df348eea86 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Fri, 27 Mar 2026 11:05:57 +0900 Subject: [PATCH] hostname: reduce range of unsafe --- src/uu/hostname/src/hostname.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/uu/hostname/src/hostname.rs b/src/uu/hostname/src/hostname.rs index 70c20e780f3..747f7794894 100644 --- a/src/uu/hostname/src/hostname.rs +++ b/src/uu/hostname/src/hostname.rs @@ -38,10 +38,8 @@ mod wsa { pub(super) struct WsaHandle(()); pub(super) fn start() -> io::Result { - let err = unsafe { - let mut data = std::mem::MaybeUninit::::uninit(); - WSAStartup(0x0202, data.as_mut_ptr()) - }; + let mut data = std::mem::MaybeUninit::::uninit(); + let err = unsafe { WSAStartup(0x0202, data.as_mut_ptr()) }; if err == 0 { Ok(WsaHandle(())) } else { @@ -51,10 +49,8 @@ mod wsa { impl Drop for WsaHandle { fn drop(&mut self) { - unsafe { - // This possibly returns an error but we can't handle it - let _err = WSACleanup(); - } + // This possibly returns an error but we can't handle it + let _ = unsafe { WSACleanup() }; } } }