From cc29216ea9666428885771ea05361a9c62ab7a10 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Wed, 10 Dec 2025 22:14:38 +0000 Subject: [PATCH] fix: clippy::ptr_cast_constness https://rust-lang.github.io/rust-clippy/master/index.html#ptr_cast_constness Part of #12136 --- src/exec.rs | 2 +- src/fork_exec/spawn.rs | 4 ++-- src/global_safety.rs | 8 +++----- src/locale.rs | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/exec.rs b/src/exec.rs index 83dab7871..af5dfb775 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -415,7 +415,7 @@ fn safe_launch_process( // +1 for /bin/sh, +1 for terminating nullptr let mut argv2 = [std::ptr::null(); 1 + MAXARGS + 1]; let bshell = PATH_BSHELL.as_ptr() as *const c_char; - argv2[0] = bshell as *mut c_char; + argv2[0] = bshell; argv2[1..argv.len() + 1].copy_from_slice(argv); // The command to call should use the full path, // not what we would pass as argv0. diff --git a/src/fork_exec/spawn.rs b/src/fork_exec/spawn.rs index adbde6f41..e2b3f80f8 100644 --- a/src/fork_exec/spawn.rs +++ b/src/fork_exec/spawn.rs @@ -172,12 +172,12 @@ pub(crate) fn spawn( let cmdcstr = unsafe { CStr::from_ptr(cmd) }; if spawn_err.0 == libc::ENOEXEC && is_thompson_shell_script(cmdcstr) { // Create a new argv with /bin/sh prepended. - let mut argv2 = vec![PATH_BSHELL.as_ptr() as *mut c_char]; + let mut argv2: Vec<*mut c_char> = vec![PATH_BSHELL.as_ptr().cast_mut() as *mut c_char]; // The command to call should use the full path, // not what we would pass as argv0. let cmd2: CString = CString::new(cmdcstr.to_bytes()).unwrap(); - argv2.push(cmd2.as_ptr() as *mut c_char); + argv2.push(cmd2.as_ptr().cast_mut()); for i in 1.. { let ptr = unsafe { argv.offset(i).read() }; if ptr.is_null() { diff --git a/src/global_safety.rs b/src/global_safety.rs index 7ab8448dc..d3b9e9a34 100644 --- a/src/global_safety.rs +++ b/src/global_safety.rs @@ -35,7 +35,7 @@ fn clone(&self) -> Self { impl AtomicRef { pub const fn new(value: &'static &'static T) -> Self { - Self(AtomicPtr::new(std::ptr::from_ref(value) as *mut &'static T)) + Self(AtomicPtr::new(std::ptr::from_ref(value).cast_mut())) } pub fn load(&self) -> &'static T { @@ -43,10 +43,8 @@ pub fn load(&self) -> &'static T { } pub fn store(&self, value: &'static &'static T) { - self.0.store( - std::ptr::from_ref(value) as *mut &'static T, - Ordering::Relaxed, - ) + self.0 + .store(std::ptr::from_ref(value).cast_mut(), Ordering::Relaxed) } } diff --git a/src/locale.rs b/src/locale.rs index b3c438fd5..1d8e7fa27 100644 --- a/src/locale.rs +++ b/src/locale.rs @@ -81,7 +81,7 @@ unsafe fn lconv_to_locale(lconv: &libc::lconv) -> Locale { // Up to 4 groups. // group_cursor is terminated by either a 0 or CHAR_MAX. - let mut group_cursor = lconv.grouping as *const libc::c_char; + let mut group_cursor = lconv.grouping.cast_const(); if group_cursor.is_null() { group_cursor = empty.as_ptr(); }