Merge branch 'clippy-green3' into 'master'

tackle more clippy lints for redox

See merge request redox-os/relibc!1549
This commit is contained in:
Jeremy Soller
2026-07-15 10:27:40 -06:00
15 changed files with 97 additions and 70 deletions
+2 -2
View File
@@ -68,13 +68,13 @@ impl<'a> From<&'a syscall::TimeSpec> for timespec {
fn from(value: &'a syscall::TimeSpec) -> Self {
Self {
tv_sec: value.tv_sec as _,
tv_nsec: value.tv_nsec as _,
tv_nsec: value.tv_nsec.into(),
}
}
}
#[cfg(target_os = "redox")]
impl<'a> From<&'a timespec> for syscall::TimeSpec {
impl From<&timespec> for syscall::TimeSpec {
fn from(tp: &timespec) -> Self {
Self {
tv_sec: tp.tv_sec as _,
+1 -1
View File
@@ -5,7 +5,7 @@ pub fn split(line: &mut [u8]) -> Option<passwd> {
let mut parts = line.split_mut(|&c| c == b'\0');
Some(passwd {
pw_name: parts.next()?.as_mut_ptr().cast::<c_char>(),
pw_passwd: c"x".as_ptr() as *const c_char as *mut c_char,
pw_passwd: c"x".as_ptr().cast::<c_char>().cast_mut(),
pw_uid: parsed(parts.next())?,
pw_gid: parsed(parts.next())?,
pw_gecos: parts.next()?.as_mut_ptr().cast::<c_char>(),
+16 -16
View File
@@ -22,7 +22,9 @@ fn dup_read<T>(fd: c_int, name: &str, t: &mut T) -> syscall::Result<usize> {
let size = mem::size_of::<T>();
let bytes = dup.read(unsafe { slice::from_raw_parts_mut(t as *mut T as *mut u8, size) })?;
let bytes = dup.read(unsafe {
slice::from_raw_parts_mut(core::ptr::from_mut::<T>(t).cast::<u8>(), size)
})?;
Ok(bytes / size)
}
@@ -33,7 +35,8 @@ fn dup_write<T>(fd: c_int, name: &str, t: &T) -> Result<usize> {
let size = mem::size_of::<T>();
let bytes = dup.write(unsafe { slice::from_raw_parts(t as *const T as *const u8, size) })?;
let bytes = dup
.write(unsafe { slice::from_raw_parts(core::ptr::from_ref::<T>(t).cast::<u8>(), size) })?;
Ok(bytes / size)
}
@@ -50,13 +53,13 @@ impl IoctlBuffer {
unsafe fn read<T>(&self) -> Result<T> {
let (ptr, size) = match *self {
Self::Write(ptr, size) => (ptr, size),
Self::ReadWrite(ptr, size) => (ptr as *const c_void, size),
Self::ReadWrite(ptr, size) => (ptr.cast_const(), size),
_ => {
return Err(Errno(EINVAL));
}
};
if size == mem::size_of::<T>() {
let value = unsafe { ptr::read(ptr as *const T) };
let value = unsafe { ptr::read(ptr.cast::<T>()) };
Ok(value)
} else {
Err(Errno(EINVAL))
@@ -64,14 +67,11 @@ impl IoctlBuffer {
}
unsafe fn write<T>(&mut self, value: T) -> Result<()> {
let (ptr, size) = match *self {
Self::Read(ptr, size) | Self::ReadWrite(ptr, size) => (ptr, size),
_ => {
return Err(Errno(EINVAL));
}
let (Self::Read(ptr, size) | Self::ReadWrite(ptr, size)) = *self else {
return Err(Errno(EINVAL));
};
if size == mem::size_of::<T>() {
unsafe { ptr::write(ptr as *mut T, value) };
unsafe { ptr::write(ptr.cast::<T>(), value) };
Ok(())
} else {
Err(Errno(EINVAL))
@@ -83,7 +83,7 @@ pub unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Resu
match request {
FIONBIO => {
let mut flags = Sys::fcntl(fd, fcntl::F_GETFL, 0)?;
flags = if unsafe { *(out as *mut c_int) } == 0 {
flags = if unsafe { *out.cast::<c_int>() } == 0 {
flags & !fcntl::O_NONBLOCK
} else {
flags | fcntl::O_NONBLOCK
@@ -91,7 +91,7 @@ pub unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Resu
Sys::fcntl(fd, fcntl::F_SETFL, flags as c_ulonglong)?;
}
TCGETS => {
let termios = unsafe { &mut *(out as *mut termios::termios) };
let termios = unsafe { &mut *out.cast::<termios::termios>() };
dup_read(fd, "termios", termios)?;
}
// TODO: give these different behaviors
@@ -119,7 +119,7 @@ pub unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Resu
todo_skip!(0, "ioctl TIOCSCTTY");
}
TIOCGPGRP => {
let pgrp = unsafe { &mut *(out as *mut pid_t) };
let pgrp = unsafe { &mut *out.cast::<pid_t>() };
dup_read(fd, "pgrp", pgrp)?;
}
TIOCSPGRP => {
@@ -127,7 +127,7 @@ pub unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Resu
dup_write(fd, "pgrp", pgrp)?;
}
TIOCGWINSZ => {
let winsize = unsafe { &mut *(out as *mut winsize) };
let winsize = unsafe { &mut *out.cast::<winsize>() };
dup_read(fd, "winsize", winsize)?;
}
TIOCSWINSZ => {
@@ -135,7 +135,7 @@ pub unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Resu
dup_write(fd, "winsize", winsize)?;
}
TIOCGPTLCK => {
let lock = unsafe { &mut *(out as *mut c_int) };
let lock = unsafe { &mut *out.cast::<c_int>() };
dup_read(fd, "ptlock", lock)?;
}
TIOCSPTLCK => {
@@ -143,7 +143,7 @@ pub unsafe fn ioctl_inner(fd: c_int, request: c_ulong, out: *mut c_void) -> Resu
dup_write(fd, "ptlock", lock)?;
}
TIOCGPTN => {
let name = unsafe { &mut *(out as *mut c_int) };
let name = unsafe { &mut *out.cast::<c_int>() };
dup_read(fd, "ptsname", name)?;
}
SIOCATMARK => {
+1 -1
View File
@@ -72,7 +72,7 @@ pub(crate) struct timer_internal_t {
#[cfg(target_os = "redox")]
impl timer_internal_t {
pub unsafe fn from_raw(timerid: timer_t) -> &'static mut Self {
unsafe { &mut *(timerid as *mut Self) }
unsafe { &mut *timerid.cast::<Self>() }
}
}
+3 -1
View File
@@ -1,4 +1,6 @@
/// sysconf.h: <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sysconf.html>.
//! `sysconf.h` implementation.
//!
//! See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sysconf.html>.
#[cfg(target_os = "redox")]
#[path = "sysconf/redox.rs"]
+3 -3
View File
@@ -40,7 +40,7 @@ pub(super) fn sysconf_impl(name: c_int) -> c_long {
_SC_TIMEOUTS => 202405,
_SC_TIMERS => 202405,
_SC_SYMLOOP_MAX => -1,
_SC_HOST_NAME_MAX => limits::HOST_NAME_MAX.try_into().unwrap_or(-1),
_SC_HOST_NAME_MAX => limits::HOST_NAME_MAX,
_SC_NPROCESSORS_CONF => get_cpu_count().unwrap_or(None).unwrap_or(1),
_SC_NPROCESSORS_ONLN => get_cpu_count().unwrap_or(None).unwrap_or(1),
_SC_PHYS_PAGES => get_mem_stat().map(|s| s.f_blocks as c_long).unwrap_or(-1),
@@ -77,6 +77,6 @@ pub fn get_mem_stat() -> Result<sys_statvfs::statvfs, Errno> {
let mut buf = sys_statvfs::statvfs::default();
let res = Sys::fstatvfs(fd, Out::from_mut(&mut buf));
if let Ok(()) = Sys::close(fd) {}; // TODO handle error
let _ = res?;
return Ok(buf);
res?;
Ok(buf)
}