From 0f1124ae25b36edb2f8dca53f7002baa18c35fbe Mon Sep 17 00:00:00 2001 From: auronandace Date: Wed, 18 Feb 2026 09:26:39 +0000 Subject: [PATCH] cleanup getopt casting --- Cargo.toml | 2 +- src/header/getopt/mod.rs | 34 +++++++++++++++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cb0f88b9f6..c6a3aab045 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ exclude = ["tests", "dlmalloc-rs"] [workspace.lints.clippy] cast_lossless = "warn" # TODO review occurrences -cast_ptr_alignment = "allow" # TODO change to warn or deny when ready to fix +cast_ptr_alignment = "warn" # TODO review occurrences missing_safety_doc = "allow" # TODO review occurrences mut_from_ref = "allow" # TODO review occurrences ptr_as_ptr = "warn" # TODO review occurrences diff --git a/src/header/getopt/mod.rs b/src/header/getopt/mod.rs index 062d17b6b2..a9bc12e15a 100644 --- a/src/header/getopt/mod.rs +++ b/src/header/getopt/mod.rs @@ -110,19 +110,19 @@ pub unsafe extern "C" fn getopt_long( optarg = *argv.offset(optind as isize); optind += 1; } else if *optstring == b':' as c_char { - return b':' as c_int; + return c_int::from(b':'); } else { - stdio::fputs(*argv as _, &mut *stdio::stderr); + stdio::fputs((*argv).cast_const(), &mut *stdio::stderr); stdio::fputs( - ": option '--\0".as_ptr() as _, + c": option '--".as_ptr().cast(), &mut *stdio::stderr, ); stdio::fputs(current_arg, &mut *stdio::stderr); stdio::fputs( - "' requires an argument\n\0".as_ptr() as _, + c"' requires an argument\n".as_ptr().cast(), &mut *stdio::stderr, ); - return b'?' as c_int; + return c_int::from(b'?'); } } } @@ -160,26 +160,26 @@ 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 as _, &mut *stdio::stderr); - stdio::fputs(desc.as_ptr() as _, &mut *stdio::stderr); - stdio::fputc(*current_arg as _, &mut *stdio::stderr); - stdio::fputc(b'\n' as _, &mut *stdio::stderr); + 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); }; match unsafe { find_option(*current_arg, optstring) } { Some(GetoptOption::Flag) => { update_current_opt(); - unsafe { *current_arg as c_int } + unsafe { c_int::from(*current_arg) } } Some(GetoptOption::OptArg) => unsafe { - CURRENT_OPT = b"\0".as_ptr() as _; + CURRENT_OPT = c"".as_ptr().cast_mut(); if *current_arg.offset(1) == 0 { optind += 2; if optind > argc { CURRENT_OPT = ptr::null_mut(); - optopt = *current_arg as c_int; + optopt = c_int::from(*current_arg); let errch = if *optstring == b':' as c_char { b':' } else { @@ -189,17 +189,17 @@ unsafe fn parse_arg( b'?' }; - errch as c_int + c_int::from(errch) } else { optarg = *argv.offset(optind as isize - 1); - *current_arg as c_int + c_int::from(*current_arg) } } else { optarg = current_arg.offset(1); optind += 1; - *current_arg as c_int + c_int::from(*current_arg) } }, None => { @@ -211,9 +211,9 @@ unsafe fn parse_arg( update_current_opt(); unsafe { - optopt = *current_arg as c_int; + optopt = c_int::from(*current_arg); } - b'?' as c_int + c_int::from(b'?') } } }