diff --git a/src/header/arpa_inet/mod.rs b/src/header/arpa_inet/mod.rs index cc46168044..0983743fb2 100644 --- a/src/header/arpa_inet/mod.rs +++ b/src/header/arpa_inet/mod.rs @@ -64,10 +64,10 @@ pub unsafe extern "C" fn inet_aton(cp: *const c_char, inp: *mut in_addr) -> c_in // While it is true that C2Y accepts 0o and 0O as octal prefixes, C17 doesn't // The POSIX spec defers to C17 // see https://pubs.opengroup.org/onlinepubs/9799919799/functions/inet_addr.html - _ => u32::from_str_radix(&hex_or_oct, 8), + _ => u32::from_str_radix(hex_or_oct, 8), } } else { - u32::from_str_radix(&part, 10) + part.parse::() } } { if parts_iter.peek().is_some() { diff --git a/src/header/locale/data.rs b/src/header/locale/data.rs index 128f39a184..7be2b64cac 100644 --- a/src/header/locale/data.rs +++ b/src/header/locale/data.rs @@ -288,11 +288,7 @@ impl PosixLocaleDef { let mut locale = PosixLocaleDef::default(); let mut lines = content.lines(); - loop { - let Some(line) = lines.next() else { - break; - }; - + while let Some(line) = lines.next() { let trimmed = line.trim(); if trimmed.is_empty() || trimmed.starts_with('#') { continue; @@ -303,10 +299,7 @@ impl PosixLocaleDef { continue; }; let mut val: String = String::new(); - loop { - let Some(chunk) = parts.next() else { - break; - }; + while let Some(chunk) = parts.next() { if !chunk.ends_with('\\') { val.push_str(chunk); break; diff --git a/src/header/pty/mod.rs b/src/header/pty/mod.rs index 739d423dbe..1d132aa141 100644 --- a/src/header/pty/mod.rs +++ b/src/header/pty/mod.rs @@ -42,7 +42,7 @@ unsafe fn openpty_inner(name: &mut [u8]) -> Result<(c_int, c_int), ()> { let slave = unsafe { fcntl::open( - name.as_ptr() as *const c_char, + name.as_ptr().cast::(), fcntl::O_RDWR | fcntl::O_NOCTTY, 0, ) diff --git a/src/header/stdio/constants.rs b/src/header/stdio/constants.rs index 19fe69064e..ad2153f96d 100644 --- a/src/header/stdio/constants.rs +++ b/src/header/stdio/constants.rs @@ -16,7 +16,7 @@ pub const F_SVB: c_int = 64; pub const F_APP: c_int = 128; pub const F_BADJ: c_int = 256; -/// SEEK_SET, SEEK_CUR and SEEK_END defined in fcntl bits header +// SEEK_SET, SEEK_CUR and SEEK_END defined in fcntl bits header pub const _IOFBF: c_int = 0; pub const _IOLBF: c_int = 1; diff --git a/src/header/stdio/printf.rs b/src/header/stdio/printf.rs index 0087aa42da..57ea79db09 100644 --- a/src/header/stdio/printf.rs +++ b/src/header/stdio/printf.rs @@ -192,11 +192,11 @@ impl VaArg { } let ap_impl = unsafe { - let ptr_to_struct = ap as *mut core::ffi::VaList as *mut VaListInner; + let ptr_to_struct = core::ptr::from_mut::(ap).cast::(); &mut *ptr_to_struct }; - let ptr = ap_impl.overflow_arg_area as *const c_longdouble; + let ptr = ap_impl.overflow_arg_area.cast::(); let val = unsafe { ptr.read() }; ap_impl.overflow_arg_area = unsafe { ap_impl.overflow_arg_area.add(16) }; diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs index 14b8f46f8f..39769c4909 100644 --- a/src/header/stdlib/mod.rs +++ b/src/header/stdlib/mod.rs @@ -368,7 +368,7 @@ pub unsafe extern "C" fn exit(status: c_int) -> ! { } // Look for the neighbor functions in memory until the end - let mut f = unsafe { &__fini_array_end } as *const _; + let mut f = core::ptr::from_ref(unsafe { &__fini_array_end }); #[allow(clippy::op_ref)] while f > &raw const __fini_array_start { f = unsafe { f.offset(-1) }; diff --git a/src/header/sys_select/mod.rs b/src/header/sys_select/mod.rs index e4fd546dc0..8296410b9c 100644 --- a/src/header/sys_select/mod.rs +++ b/src/header/sys_select/mod.rs @@ -38,7 +38,7 @@ pub struct fd_set { } #[allow(clippy::needless_update)] -pub fn select_epoll( +pub unsafe fn select_epoll( nfds: c_int, readfds: Option<&mut fd_set>, writefds: Option<&mut fd_set>, @@ -188,30 +188,32 @@ pub unsafe extern "C" fn select( timeout: *mut timeval, ) -> c_int { trace_expr!( - select_epoll( - nfds, - if readfds.is_null() { - None - } else { - Some(unsafe { &mut *readfds }) - }, - if writefds.is_null() { - None - } else { - Some(unsafe { &mut *writefds }) - }, - if exceptfds.is_null() { - None - } else { - Some(unsafe { &mut *exceptfds }) - }, - if timeout.is_null() { - None - } else { - Some(unsafe { &mut *timeout }) - }, - core::ptr::null(), - ), + unsafe { + select_epoll( + nfds, + if readfds.is_null() { + None + } else { + Some(&mut *readfds) + }, + if writefds.is_null() { + None + } else { + Some(&mut *writefds) + }, + if exceptfds.is_null() { + None + } else { + Some(&mut *exceptfds) + }, + if timeout.is_null() { + None + } else { + Some(&mut *timeout) + }, + core::ptr::null(), + ) + }, "select({}, {:p}, {:p}, {:p}, {:p})", nfds, readfds, @@ -242,26 +244,28 @@ pub unsafe extern "C" fn pselect( } }; trace_expr!( - select_epoll( - nfds, - if readfds.is_null() { - None - } else { - Some(unsafe { &mut *readfds }) - }, - if writefds.is_null() { - None - } else { - Some(unsafe { &mut *writefds }) - }, - if exceptfds.is_null() { - None - } else { - Some(unsafe { &mut *exceptfds }) - }, - micro_timeout.as_mut(), - sigmask - ), + unsafe { + select_epoll( + nfds, + if readfds.is_null() { + None + } else { + Some(&mut *readfds) + }, + if writefds.is_null() { + None + } else { + Some(&mut *writefds) + }, + if exceptfds.is_null() { + None + } else { + Some(&mut *exceptfds) + }, + micro_timeout.as_mut(), + sigmask, + ) + }, "pselect({}, {:p}, {:p}, {:p}, {:p}, {:p})", nfds, readfds, diff --git a/src/header/threads/mod.rs b/src/header/threads/mod.rs index 56c24765b3..3aed687c15 100644 --- a/src/header/threads/mod.rs +++ b/src/header/threads/mod.rs @@ -137,9 +137,9 @@ pub unsafe extern "C" fn mtx_destroy(mtx: *mut mtx_t) { #[unsafe(no_mangle)] pub unsafe extern "C" fn mtx_init(mtx: *mut mtx_t, ty: c_int) -> c_int { let mut attr = MaybeUninit::::uninit(); - let _ = unsafe { + unsafe { pthread_mutexattr_init(attr.as_mut_ptr()); - }; + } let mut attr = unsafe { attr.assume_init() }; let _ = unsafe { @@ -260,7 +260,7 @@ pub unsafe extern "C" fn thrd_exit(ret: c_int) -> ! { /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn thrd_join(thrd: thrd_t, retval: *mut c_int) -> c_int { - if unsafe { pthread_join(thrd, retval as *mut *mut c_void) } == 0 { + if unsafe { pthread_join(thrd, retval.cast::<*mut c_void>()) } == 0 { thrd_success } else { thrd_error diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 6860619ebe..fc5fc9f2cb 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -823,7 +823,7 @@ pub extern "C" fn nice(incr: c_int) -> c_int { return -1; } - return new_nice; + new_nice } /// See . diff --git a/src/platform/mod.rs b/src/platform/mod.rs index f11edf3ee1..d9ec7cfee6 100644 --- a/src/platform/mod.rs +++ b/src/platform/mod.rs @@ -153,7 +153,7 @@ impl Write for StringWriter { if self.1 > 1 { let copy_size = buf.len().min(self.1 - 1); unsafe { - ptr::copy_nonoverlapping(buf.as_ptr() as _, self.0, copy_size); + ptr::copy_nonoverlapping(buf.as_ptr().cast(), self.0, copy_size); self.1 -= copy_size; self.0 = self.0.add(copy_size); diff --git a/src/pthread/mod.rs b/src/pthread/mod.rs index f2637202e9..e2833fcef6 100644 --- a/src/pthread/mod.rs +++ b/src/pthread/mod.rs @@ -52,7 +52,7 @@ pub unsafe fn init() { //const FIRST_THREAD_IDX: usize = 1; pub unsafe fn terminate_from_main_thread() { - for (_, tcb) in OS_TID_TO_PTHREAD.lock().iter() { + for tcb in OS_TID_TO_PTHREAD.lock().values() { let _ = unsafe { cancel(&(*tcb.0).pthread) }; } } diff --git a/src/start.rs b/src/start.rs index a21a35ea29..8be309d761 100644 --- a/src/start.rs +++ b/src/start.rs @@ -235,7 +235,7 @@ pub unsafe extern "C" fn relibc_start_v1( // Run preinit array { - let mut f = unsafe { &__preinit_array_start } as *const _; + let mut f = core::ptr::from_ref(unsafe { &__preinit_array_start }); #[allow(clippy::op_ref)] while f < &raw const __preinit_array_end { (unsafe { *f })(); @@ -245,7 +245,7 @@ pub unsafe extern "C" fn relibc_start_v1( // Run init array { - let mut f = unsafe { &__init_array_start } as *const _; + let mut f = core::ptr::from_ref(unsafe { &__init_array_start }); #[allow(clippy::op_ref)] while f < &raw const __init_array_end { (unsafe { *f })();