Fix many clippy lints
This commit is contained in:
@@ -96,11 +96,11 @@ pub struct group {
|
||||
#[derive(Debug)]
|
||||
enum Error {
|
||||
EOF,
|
||||
SyntaxError,
|
||||
Syntax,
|
||||
BufTooSmall,
|
||||
Misc(io::Error),
|
||||
FromUtf8Error(FromUtf8Error),
|
||||
ParseIntError(ParseIntError),
|
||||
FromUtf8(FromUtf8Error),
|
||||
ParseInt(ParseIntError),
|
||||
Other,
|
||||
}
|
||||
|
||||
@@ -171,9 +171,9 @@ fn parse_grp(line: String, destbuf: Option<DestBuffer>) -> Result<OwnedGrp, Erro
|
||||
let gr_name = buffer.next().ok_or(Error::EOF)?.to_vec();
|
||||
let gr_passwd = buffer.next().ok_or(Error::EOF)?.to_vec();
|
||||
let gr_gid = String::from_utf8(buffer.next().ok_or(Error::EOF)?.to_vec())
|
||||
.map_err(Error::FromUtf8Error)?
|
||||
.map_err(Error::FromUtf8)?
|
||||
.parse::<gid_t>()
|
||||
.map_err(Error::ParseIntError)?;
|
||||
.map_err(Error::ParseInt)?;
|
||||
|
||||
// Place the gid at the beginning of the byte buffer to make getting it back out again later, much faster.
|
||||
|
||||
@@ -338,9 +338,9 @@ pub unsafe extern "C" fn getgrgid_r(
|
||||
return match err {
|
||||
Error::BufTooSmall => ERANGE,
|
||||
Error::EOF
|
||||
| Error::SyntaxError
|
||||
| Error::FromUtf8Error(_)
|
||||
| Error::ParseIntError(_)
|
||||
| Error::Syntax
|
||||
| Error::FromUtf8(_)
|
||||
| Error::ParseInt(_)
|
||||
| Error::Other => EINVAL,
|
||||
Error::Misc(io_err) => match io_err.kind() {
|
||||
io::ErrorKind::InvalidData | io::ErrorKind::UnexpectedEof => EINVAL,
|
||||
|
||||
+6
-14
@@ -272,10 +272,8 @@ pub unsafe extern "C" fn gethostbyaddr(
|
||||
}
|
||||
|
||||
//TODO actually get aliases
|
||||
let mut _host_aliases: Vec<Vec<u8>> = Vec::new();
|
||||
_host_aliases.push(vec![b'\0']);
|
||||
let mut host_aliases: Vec<*mut c_char> = Vec::new();
|
||||
host_aliases.push(ptr::null_mut());
|
||||
let mut _host_aliases: Vec<Vec<u8>> = vec![vec![b'\0']];
|
||||
let mut host_aliases: Vec<*mut c_char> = vec![ptr::null_mut()];
|
||||
unsafe { HOST_ALIASES.unsafe_set(Some(_host_aliases)) };
|
||||
|
||||
match lookup_addr(addr.clone()).map(|host_names| host_names.into_iter().next()) {
|
||||
@@ -402,11 +400,8 @@ pub unsafe extern "C" fn gethostbyname(name: *const c_char) -> *mut hostent {
|
||||
unsafe { HOST_ADDR = Some(host_addr) };
|
||||
|
||||
//TODO actually get aliases
|
||||
let mut _host_aliases: Vec<Vec<u8>> = Vec::new();
|
||||
_host_aliases.push(vec![b'\0']);
|
||||
let mut host_aliases: Vec<*mut c_char> = Vec::new();
|
||||
host_aliases.push(ptr::null_mut());
|
||||
host_aliases.push(ptr::null_mut());
|
||||
let mut _host_aliases: Vec<Vec<u8>> = vec![vec![b'\0']];
|
||||
let mut host_aliases: Vec<*mut c_char> = vec![ptr::null_mut(); 2];
|
||||
unsafe { HOST_ALIASES.unsafe_set(Some(_host_aliases)) };
|
||||
|
||||
unsafe {
|
||||
@@ -769,11 +764,8 @@ pub unsafe extern "C" fn getservent() -> *mut servent {
|
||||
*serv_aliases.push(ptr::null_mut());
|
||||
*
|
||||
*/
|
||||
let mut _serv_aliases: Vec<Vec<u8>> = Vec::new();
|
||||
_serv_aliases.push(vec![b'\0']);
|
||||
let mut serv_aliases: Vec<*mut i8> = Vec::new();
|
||||
serv_aliases.push(ptr::null_mut());
|
||||
serv_aliases.push(ptr::null_mut());
|
||||
let mut _serv_aliases: Vec<Vec<u8>> = vec![vec![b'\0']];
|
||||
let mut serv_aliases: Vec<*mut i8> = vec![ptr::null_mut(); 2];
|
||||
|
||||
unsafe { SERV_ALIASES.unsafe_set(Some(_serv_aliases)) };
|
||||
unsafe { SERV_NAME.unsafe_set(Some(serv_name)) };
|
||||
|
||||
@@ -95,6 +95,7 @@ pub unsafe fn poll_epoll(fds: &mut [pollfd], timeout: c_int, sigmask: *const sig
|
||||
continue;
|
||||
}
|
||||
|
||||
#[expect(clippy::needless_update)]
|
||||
let mut event = epoll_event {
|
||||
events: 0,
|
||||
data: epoll_data { u64: i as u64 },
|
||||
|
||||
@@ -357,7 +357,6 @@ pub extern "C" fn signal(
|
||||
};
|
||||
let mut old_sa = mem::MaybeUninit::uninit();
|
||||
if unsafe { sigaction(sig, &raw const sa, old_sa.as_mut_ptr()) } < 0 {
|
||||
mem::forget(old_sa);
|
||||
return unsafe { mem::transmute(SIG_ERR) };
|
||||
}
|
||||
unsafe { old_sa.assume_init() }.sa_handler
|
||||
@@ -467,7 +466,6 @@ pub unsafe extern "C" fn sigset(
|
||||
if unsafe { sigaction(sig, ptr::null_mut(), old_sa.as_mut_ptr()) } < 0
|
||||
|| unsafe { sigprocmask(SIG_BLOCK, &raw const set, &raw mut set) } < 0
|
||||
{
|
||||
mem::forget(old_sa);
|
||||
return sig_err;
|
||||
}
|
||||
} else {
|
||||
@@ -481,7 +479,6 @@ pub unsafe extern "C" fn sigset(
|
||||
if unsafe { sigaction(sig, &raw const sa, old_sa.as_mut_ptr()) } < 0
|
||||
|| unsafe { sigprocmask(SIG_UNBLOCK, &raw const set, &raw mut set) } < 0
|
||||
{
|
||||
mem::forget(old_sa);
|
||||
return sig_err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ impl VaArg {
|
||||
|
||||
let ap_impl = unsafe {
|
||||
// The double deconstruct is intended
|
||||
let ptr_to_struct = *(ap as *mut core::ffi::VaList as *mut *mut VaListImpl);
|
||||
let ptr_to_struct = *(core::ptr::from_mut(ap).cast::<*mut VaListImpl>());
|
||||
&mut *ptr_to_struct
|
||||
};
|
||||
|
||||
@@ -487,6 +487,7 @@ fn float_exp(mut float: c_double) -> (c_double, isize) {
|
||||
(float, exp)
|
||||
}
|
||||
|
||||
#[expect(clippy::too_many_arguments)]
|
||||
fn fmt_float_exp<W: Write>(
|
||||
w: &mut W,
|
||||
exp_fmt: char,
|
||||
@@ -524,6 +525,7 @@ fn fmt_float_exp<W: Write>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[expect(clippy::too_many_arguments)]
|
||||
fn fmt_float_normal<W: Write>(
|
||||
w: &mut W,
|
||||
trim: bool,
|
||||
|
||||
@@ -92,17 +92,7 @@ impl<L: LogSink> LogParams<L> {
|
||||
.unwrap_or(true)
|
||||
{
|
||||
// Try reopening the log file once and retrying as musl does.
|
||||
if !self
|
||||
.open_logger()
|
||||
.is_ok()
|
||||
.then(|| {
|
||||
self.writer
|
||||
.as_mut()
|
||||
.map(|w| w.writer().write_all(&buffer).is_ok())
|
||||
.unwrap_or_default()
|
||||
})
|
||||
.unwrap_or_default()
|
||||
&& self.opt.contains(Config::Console)
|
||||
if !(self.open_logger().is_ok() && self.writer.as_mut().and_then(|w| w.writer().write_all(&buffer).ok()).is_some()) && self.opt.contains(Config::Console)
|
||||
{
|
||||
// TODO: Log error to /dev/console & Redox equivalent
|
||||
}
|
||||
@@ -139,10 +129,10 @@ impl<L: LogSink> LogParams<L> {
|
||||
/// default.
|
||||
pub fn set_identity(&mut self, ident: Option<&str>) {
|
||||
self.ident = ident
|
||||
.and_then(|ident| {
|
||||
.map(|ident| {
|
||||
let ident = ident.bytes().chain([0]).collect();
|
||||
// SAFETY: Already validated
|
||||
Some(unsafe { String::from_utf8_unchecked(ident) })
|
||||
unsafe { String::from_utf8_unchecked(ident) }
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
unsafe { CStr::from_nullable_ptr(platform::program_invocation_short_name) }
|
||||
|
||||
+25
-36
@@ -256,6 +256,7 @@ pub extern "C" fn clock() -> clock_t {
|
||||
}
|
||||
let ts = unsafe { ts.assume_init() };
|
||||
|
||||
#[expect(clippy::unnecessary_cast, reason="needed on i586")]
|
||||
let clocks =
|
||||
ts.tv_sec * CLOCKS_PER_SEC as i64 + (ts.tv_nsec / (1_000_000_000 / CLOCKS_PER_SEC)) as i64;
|
||||
clock_t::try_from(clocks).unwrap_or(-1)
|
||||
@@ -712,18 +713,12 @@ unsafe fn clear_timezone(guard: &mut MutexGuard<'_, (Option<CString>, Option<CSt
|
||||
|
||||
// SAFETY: the caller is required to ensure access exclusively for the
|
||||
// holder of `TIMEZONE_LOCK`.
|
||||
let daylight_mut = unsafe { &mut *(&raw mut daylight) };
|
||||
// SAFETY: the caller is required to ensure access exclusively for the
|
||||
// holder of `TIMEZONE_LOCK`.
|
||||
let timezone_mut = unsafe { &mut *(&raw mut timezone) };
|
||||
// SAFETY: the caller is required to ensure access exclusively for the
|
||||
// holder of `TIMEZONE_LOCK`.
|
||||
let tzname_mut = unsafe { &mut *(&raw mut tzname) };
|
||||
|
||||
(*tzname_mut).0[0] = ptr::null_mut();
|
||||
(*tzname_mut).0[1] = ptr::null_mut();
|
||||
*timezone_mut = 0;
|
||||
*daylight_mut = 0;
|
||||
unsafe {
|
||||
tzname.0[0] = ptr::null_mut();
|
||||
tzname.0[1] = ptr::null_mut();
|
||||
timezone = 0;
|
||||
daylight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
@@ -848,34 +843,28 @@ unsafe fn set_timezone(
|
||||
) {
|
||||
// SAFETY: the caller is required to ensure access exclusively for the
|
||||
// holder of `TIMEZONE_LOCK`.
|
||||
let daylight_mut = unsafe { &mut *(&raw mut daylight) };
|
||||
// SAFETY: the caller is required to ensure access exclusively for the
|
||||
// holder of `TIMEZONE_LOCK`.
|
||||
let timezone_mut = unsafe { &mut *(&raw mut timezone) };
|
||||
// SAFETY: the caller is required to ensure access exclusively for the
|
||||
// holder of `TIMEZONE_LOCK`.
|
||||
let tzname_mut = unsafe { &mut *(&raw mut tzname) };
|
||||
unsafe {
|
||||
let ut_offset = std.offset();
|
||||
|
||||
let ut_offset = std.offset();
|
||||
guard.0 = Some(CString::new(ut_offset.abbreviation().expect("Wrong timezone")).unwrap());
|
||||
tzname.0[0] = guard.0.as_ref().unwrap().as_ptr().cast_mut();
|
||||
|
||||
guard.0 = Some(CString::new(ut_offset.abbreviation().expect("Wrong timezone")).unwrap());
|
||||
tzname_mut.0[0] = guard.0.as_ref().unwrap().as_ptr().cast_mut();
|
||||
|
||||
match dst {
|
||||
Some(dst) => {
|
||||
guard.1 =
|
||||
Some(CString::new(dst.offset().abbreviation().expect("Wrong timezone")).unwrap());
|
||||
tzname_mut.0[1] = guard.1.as_ref().unwrap().as_ptr().cast_mut();
|
||||
*daylight_mut = 1;
|
||||
}
|
||||
None => {
|
||||
guard.1 = None;
|
||||
tzname_mut.0[1] = guard.0.as_ref().unwrap().as_ptr().cast_mut();
|
||||
*daylight_mut = 0;
|
||||
match dst {
|
||||
Some(dst) => {
|
||||
guard.1 =
|
||||
Some(CString::new(dst.offset().abbreviation().expect("Wrong timezone")).unwrap());
|
||||
tzname.0[1] = guard.1.as_ref().unwrap().as_ptr().cast_mut();
|
||||
daylight = 1;
|
||||
}
|
||||
None => {
|
||||
guard.1 = None;
|
||||
tzname.0[1] = guard.0.as_ref().unwrap().as_ptr().cast_mut();
|
||||
daylight = 0;
|
||||
}
|
||||
}
|
||||
|
||||
timezone = -c_long::from(ut_offset.fix().local_minus_utc());
|
||||
}
|
||||
|
||||
*timezone_mut = -c_long::from(ut_offset.fix().local_minus_utc());
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
||||
@@ -39,12 +39,12 @@ pub const _PC_2_SYMLINKS: c_int = 20;
|
||||
fn pc(name: c_int) -> c_long {
|
||||
// Settings from musl, some adjusted
|
||||
match name {
|
||||
_PC_LINK_MAX => LINK_MAX.try_into().unwrap_or(-1),
|
||||
_PC_MAX_CANON => MAX_CANON.try_into().unwrap_or(-1),
|
||||
_PC_MAX_INPUT => MAX_INPUT.try_into().unwrap_or(-1),
|
||||
_PC_LINK_MAX => LINK_MAX,
|
||||
_PC_MAX_CANON => MAX_CANON,
|
||||
_PC_MAX_INPUT => MAX_INPUT,
|
||||
_PC_NAME_MAX => NAME_MAX.try_into().unwrap_or(-1),
|
||||
_PC_PATH_MAX => PATH_MAX.try_into().unwrap_or(-1),
|
||||
_PC_PIPE_BUF => PIPE_BUF.try_into().unwrap_or(-1),
|
||||
_PC_PIPE_BUF => PIPE_BUF,
|
||||
_PC_CHOWN_RESTRICTED => 1,
|
||||
_PC_NO_TRUNC => 1,
|
||||
_PC_VDISABLE => _POSIX_VDISABLE.into(),
|
||||
@@ -52,13 +52,13 @@ fn pc(name: c_int) -> c_long {
|
||||
_PC_ASYNC_IO => -1,
|
||||
_PC_PRIO_IO => -1,
|
||||
_PC_SOCK_MAXBUF => -1,
|
||||
_PC_FILESIZEBITS => FILESIZEBITS.into(),
|
||||
_PC_FILESIZEBITS => FILESIZEBITS,
|
||||
_PC_REC_INCR_XFER_SIZE => -1,
|
||||
_PC_REC_MAX_XFER_SIZE => -1,
|
||||
_PC_REC_MIN_XFER_SIZE => 4096,
|
||||
_PC_REC_XFER_ALIGN => 4096,
|
||||
_PC_ALLOC_SIZE_MIN => POSIX_ALLOC_SIZE_MIN.try_into().unwrap_or(-1),
|
||||
_PC_SYMLINK_MAX => SYMLINK_MAX.try_into().unwrap_or(-1),
|
||||
_PC_ALLOC_SIZE_MIN => POSIX_ALLOC_SIZE_MIN,
|
||||
_PC_SYMLINK_MAX => SYMLINK_MAX,
|
||||
_PC_2_SYMLINKS => 1,
|
||||
_ => {
|
||||
platform::ERRNO.set(errno::EINVAL);
|
||||
|
||||
@@ -326,7 +326,7 @@ pub(super) fn sysconf_impl(name: c_int) -> c_long {
|
||||
}
|
||||
}
|
||||
_SC_V6_LPBIG_OFFBIG => -1,
|
||||
_SC_HOST_NAME_MAX => HOST_NAME_MAX.try_into().unwrap_or(-1),
|
||||
_SC_HOST_NAME_MAX => HOST_NAME_MAX,
|
||||
_SC_TRACE => -1,
|
||||
_SC_TRACE_EVENT_FILTER => -1,
|
||||
_SC_TRACE_INHERIT => -1,
|
||||
|
||||
@@ -331,7 +331,7 @@ pub unsafe extern "C" fn vswscanf(
|
||||
unsafe {
|
||||
let format = WStr::from_ptr(format);
|
||||
let s = WStr::from_ptr(s);
|
||||
wscanf::scanf(s.into(), format.into(), __valist)
|
||||
wscanf::scanf(s.into(), format, __valist)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user