From 864d5e4795fbabd7f98ac4a722f73884d5ab93a0 Mon Sep 17 00:00:00 2001 From: Peter Limkilde Svendsen Date: Sun, 17 Nov 2024 20:19:52 +0100 Subject: [PATCH] Use only one .cast_mut() in memmem() --- src/header/string/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/header/string/mod.rs b/src/header/string/mod.rs index f7c19bffc7..ae1de489f2 100644 --- a/src/header/string/mod.rs +++ b/src/header/string/mod.rs @@ -103,7 +103,7 @@ pub unsafe extern "C" fn memmem( ) -> *mut c_void { match needlelen { // Required to satisfy spec (would otherwise cause .windows() to panic) - 0 => haystack.cast_mut(), + 0 => haystack, _ => { // SAFETY: the caller is required to ensure that the provided // pointers are valid. @@ -117,11 +117,12 @@ pub unsafe extern "C" fn memmem( .windows(needlelen) .find(|&haystack_window| haystack_window == needle_slice) { - Some(match_slice) => match_slice.as_ptr().cast_mut().cast(), - None => ptr::null_mut(), + Some(match_slice) => match_slice.as_ptr().cast(), + None => ptr::null(), } } } + .cast_mut() } #[no_mangle]