diff --git a/src/header/bits_time/mod.rs b/src/header/bits_time/mod.rs index 3be2fffc83..801ed63d00 100644 --- a/src/header/bits_time/mod.rs +++ b/src/header/bits_time/mod.rs @@ -15,6 +15,7 @@ impl timespec { // TODO: Write test /// similar logic with timeradd + #[allow(clippy::should_implement_trait)] // not to confuse std::ops::Add pub fn add(base: timespec, interval: timespec) -> Option { let delta_sec = base.tv_sec.checked_add(interval.tv_sec)?; let delta_nsec = base.tv_nsec.checked_add(interval.tv_nsec)?; diff --git a/src/header/getopt/mod.rs b/src/header/getopt/mod.rs index a9bc12e15a..d60e079e57 100644 --- a/src/header/getopt/mod.rs +++ b/src/header/getopt/mod.rs @@ -112,15 +112,15 @@ pub unsafe extern "C" fn getopt_long( } else if *optstring == b':' as c_char { return c_int::from(b':'); } else { - stdio::fputs((*argv).cast_const(), &mut *stdio::stderr); + stdio::fputs((*argv).cast_const(), &raw mut *stdio::stderr); stdio::fputs( c": option '--".as_ptr().cast(), - &mut *stdio::stderr, + &raw mut *stdio::stderr, ); - stdio::fputs(current_arg, &mut *stdio::stderr); + stdio::fputs(current_arg, &raw mut *stdio::stderr); stdio::fputs( c"' requires an argument\n".as_ptr().cast(), - &mut *stdio::stderr, + &raw mut *stdio::stderr, ); return c_int::from(b'?'); } @@ -160,10 +160,10 @@ unsafe fn parse_arg( let print_error = |desc: &[u8]| unsafe { // NOTE: we don't use fprintf to get around the usage of va_list - stdio::fputs((*argv).cast_const(), &mut *stdio::stderr); - stdio::fputs(desc.as_ptr().cast(), &mut *stdio::stderr); - stdio::fputc((*current_arg).into(), &mut *stdio::stderr); - stdio::fputc(b'\n'.into(), &mut *stdio::stderr); + stdio::fputs((*argv).cast_const(), &raw mut *stdio::stderr); + stdio::fputs(desc.as_ptr().cast(), &raw mut *stdio::stderr); + stdio::fputc((*current_arg).into(), &raw mut *stdio::stderr); + stdio::fputc(b'\n'.into(), &raw mut *stdio::stderr); }; match unsafe { find_option(*current_arg, optstring) } { diff --git a/src/header/glob/mod.rs b/src/header/glob/mod.rs index 1b5d297ee0..fcbaa7f7b0 100644 --- a/src/header/glob/mod.rs +++ b/src/header/glob/mod.rs @@ -268,10 +268,8 @@ fn list_dir( // Restore the old errno platform::ERRNO.set(old_errno); - if errno != 0 { - if unsafe { errfunc(path.as_ptr(), errno) } != 0 || abort_on_error { - return Err(GLOB_ABORTED); - } + if errno != 0 && (unsafe { errfunc(path.as_ptr(), errno) } != 0 || abort_on_error) { + return Err(GLOB_ABORTED); } Ok(results) diff --git a/src/header/wchar/lookaheadreader.rs b/src/header/wchar/lookaheadreader.rs index 308bb6352f..0c2490a5ba 100644 --- a/src/header/wchar/lookaheadreader.rs +++ b/src/header/wchar/lookaheadreader.rs @@ -87,7 +87,7 @@ impl<'a> LookAheadFile<'a> { let mut wc: wchar_t = 0; unsafe { mbrtowc( - &mut wc, + &raw mut wc, buf.as_ptr().cast::(), encoded_length, ptr::null_mut(), diff --git a/src/header/wchar/mod.rs b/src/header/wchar/mod.rs index 2917afa9fb..ff21b4eebc 100644 --- a/src/header/wchar/mod.rs +++ b/src/header/wchar/mod.rs @@ -49,7 +49,7 @@ pub unsafe extern "C" fn btowc(c: c_int) -> wint_t { let mut ps: mbstate_t = mbstate_t; let mut wc: wchar_t = 0; let saved_errno = platform::ERRNO.get(); - let status = unsafe { mbrtowc(&mut wc, ptr::from_ref::(&c), 1, &mut ps) }; + let status = unsafe { mbrtowc(&raw mut wc, ptr::from_ref::(&c), 1, &raw mut ps) }; if status == usize::MAX || status == usize::MAX - 1 { platform::ERRNO.set(saved_errno); return WEOF; @@ -101,7 +101,7 @@ pub unsafe extern "C" fn fgetwc(stream: *mut FILE) -> wint_t { unsafe { mbrtowc( - &mut wc, + &raw mut wc, buf.as_ptr().cast::(), encoded_length, ptr::null_mut(), @@ -140,8 +140,8 @@ pub unsafe extern "C" fn fputwc(wc: wchar_t, stream: *mut FILE) -> wint_t { let amount = unsafe { wcrtomb(bytes.as_mut_ptr(), wc, &raw mut INTERNAL) }; - for i in 0..amount { - unsafe { fputc(c_int::from(bytes[i]), &mut *stream) }; + for b in bytes.iter().take(amount) { + unsafe { fputc(c_int::from(*b), &raw mut *stream) }; } wc as wint_t @@ -253,7 +253,7 @@ pub unsafe extern "C" fn mbsnrtowcs( while (dst_ptr.is_null() || dst_offset < dst_len) && src_offset < src_len { let ps_copy = unsafe { *ps }; let mut wc: wchar_t = 0; - let amount = unsafe { mbrtowc(&mut wc, src.add(src_offset), src_len - src_offset, ps) }; + let amount = unsafe { mbrtowc(&raw mut wc, src.add(src_offset), src_len - src_offset, ps) }; // Stop in the event a decoding error occured. if amount == -1isize as usize { @@ -305,13 +305,13 @@ pub unsafe extern "C" fn mbsrtowcs( /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn putwc(wc: wchar_t, stream: *mut FILE) -> wint_t { - unsafe { fputwc(wc, &mut *stream) } + unsafe { fputwc(wc, &raw mut *stream) } } /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn putwchar(wc: wchar_t) -> wint_t { - unsafe { fputwc(wc, &mut *stdout) } + unsafe { fputwc(wc, &raw mut *stdout) } } /// See . @@ -358,7 +358,7 @@ pub unsafe extern "C" fn ungetwc(wc: wint_t, stream: &mut FILE) -> wint_t { If we called ungetc in the non-reversed order, we would get [167, 195] */ for i in 0..amount { - unsafe { ungetc(c_int::from(bytes[amount - 1 - i]), &mut *stream) }; + unsafe { ungetc(c_int::from(bytes[amount - 1 - i]), &raw mut *stream) }; } wc @@ -392,13 +392,13 @@ pub unsafe extern "C" fn fwprintf( /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn vwprintf(format: *const wchar_t, arg: va_list) -> c_int { - unsafe { vfwprintf(&mut *stdout, format, arg) } + unsafe { vfwprintf(&raw mut *stdout, format, arg) } } /// See . #[unsafe(no_mangle)] pub unsafe extern "C" fn wprintf(format: *const wchar_t, mut __valist: ...) -> c_int { - unsafe { vfwprintf(&mut *stdout, format, __valist.as_va_list()) } + unsafe { vfwprintf(&raw mut *stdout, format, __valist.as_va_list()) } } /// See . @@ -478,7 +478,7 @@ pub unsafe extern "C" fn wcsrtombs( ) -> size_t { let mut mbs = mbstate_t {}; if st.is_null() { - st = &mut mbs; + st = &raw mut mbs; } unsafe { wcsnrtombs(s, ws, size_t::MAX, n, st) } } @@ -661,7 +661,7 @@ pub unsafe extern "C" fn wcsnrtombs( let mut mbs = mbstate_t {}; if ps.is_null() { - ps = &mut mbs; + ps = &raw mut mbs; } while read < nwc {