diff --git a/src/header/monetary/strfmon.rs b/src/header/monetary/strfmon.rs index 70d7117a3c..2320a0452f 100644 --- a/src/header/monetary/strfmon.rs +++ b/src/header/monetary/strfmon.rs @@ -13,7 +13,7 @@ use libm::{fabs, pow, round, trunc}; /// /// Returns: /// - The number of characters written (excluding the null terminator), or -1 if -/// an error occurs (e.g., invalid input, buffer overflow) +/// an error occurs (e.g., invalid input, buffer overflow) pub unsafe extern "C" fn strfmon( s: *mut c_char, // Output buffer maxsize: usize, // Maximum size of the buffer @@ -32,7 +32,7 @@ pub unsafe extern "C" fn strfmon( }; // Create a mutable slice for the output buffer - let buffer = unsafe { slice::from_raw_parts_mut(s as *mut u8, maxsize) }; + let buffer = unsafe { slice::from_raw_parts_mut(s.cast::(), maxsize) }; let mut pos = 0; let mut format_chars = format_str.chars().peekable(); @@ -302,15 +302,15 @@ fn format_monetary( // 14) checks if the user specified a total field width // - if the final result is shorter, we padd it // - if `left_justify` is true, padd on the right otherwise padd on the left - if let Some(width) = flags.field_width { - if result.len() < width { - let padding = " ".repeat(width - result.len()); - result = if flags.left_justify { - result + &padding - } else { - padding + &result - }; - } + if let Some(width) = flags.field_width + && result.len() < width + { + let padding = " ".repeat(width - result.len()); + result = if flags.left_justify { + result + &padding + } else { + padding + &result + }; } // 15) write the final string to the buffer diff --git a/src/header/net_if/mod.rs b/src/header/net_if/mod.rs index 9bc3d1ce6c..edbfedec50 100644 --- a/src/header/net_if/mod.rs +++ b/src/header/net_if/mod.rs @@ -66,7 +66,7 @@ pub unsafe extern "C" fn if_indextoname(idx: c_uint, buf: *mut c_char) -> *const /// The end of the list is determined by an if_nameindex struct having if_index 0 and if_name NULL #[unsafe(no_mangle)] pub unsafe extern "C" fn if_nameindex() -> *const if_nameindex { - &INTERFACES[0] as *const if_nameindex + core::ptr::from_ref::(&INTERFACES[0]) } /// See . @@ -76,7 +76,7 @@ pub unsafe extern "C" fn if_nameindex() -> *const if_nameindex { /// An invalid name string will return an index of 0 #[unsafe(no_mangle)] pub unsafe extern "C" fn if_nametoindex(name: *const c_char) -> c_uint { - if name == null::() { + if name.is_null() { return 0; } let name = unsafe { CStr::from_ptr(name).to_str().unwrap_or("") }; diff --git a/src/header/regex/mod.rs b/src/header/regex/mod.rs index 50d645fc60..1b8da49041 100644 --- a/src/header/regex/mod.rs +++ b/src/header/regex/mod.rs @@ -56,7 +56,7 @@ pub const REG_BADRPT: c_int = 14; #[unsafe(no_mangle)] #[linkage = "weak"] // redefined in GIT pub unsafe extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags: c_int) -> c_int { - let pat = unsafe { slice::from_raw_parts(pat as *const u8, strlen(pat)) }; + let pat = unsafe { slice::from_raw_parts(pat.cast::(), strlen(pat)) }; let res = PosixRegexBuilder::new(pat) .with_default_classes() .extended(cflags & REG_EXTENDED == REG_EXTENDED) @@ -67,7 +67,7 @@ pub unsafe extern "C" fn regcomp(out: *mut regex_t, pat: *const c_char, cflags: let re_nsub = PosixRegex::new(Cow::Borrowed(&branches)).count_groups(); unsafe { *out = regex_t { - ptr: Box::into_raw(Box::new(branches)) as *mut c_void, + ptr: Box::into_raw(Box::new(branches)).cast::(), cflags, re_nsub, @@ -109,10 +109,10 @@ pub unsafe extern "C" fn regexec( // because why not? let flags = regex.cflags | eflags; - let input = unsafe { slice::from_raw_parts(input as *const u8, strlen(input)) }; - let branches = unsafe { &*(regex.ptr as *mut Tree) }; + let input = unsafe { slice::from_raw_parts(input.cast::(), strlen(input)) }; + let branches = unsafe { &*(regex.ptr.cast::()) }; - let matches = PosixRegex::new(Cow::Borrowed(&branches)) + let matches = PosixRegex::new(Cow::Borrowed(branches)) .case_insensitive(flags & REG_ICASE == REG_ICASE) .newline(flags & REG_NEWLINE == REG_NEWLINE) .no_start(flags & REG_NOTBOL == REG_NOTBOL) @@ -165,11 +165,7 @@ pub extern "C" fn regerror( }; unsafe { - ptr::copy_nonoverlapping( - string.as_ptr(), - out as *mut u8, - string.len().min(max as usize), - ); + ptr::copy_nonoverlapping(string.as_ptr(), out.cast::(), string.len().min(max)); } string.len()