From: Philippe Antoine Date: Wed, 30 Aug 2023 09:24:24 +0000 (+0200) Subject: rust: fix clippy warnings for version 1.72.0 X-Git-Tag: suricata-7.0.1~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b235e85c689254a4ad9b930d6562e3f2167f91ff;p=thirdparty%2Fsuricata.git rust: fix clippy warnings for version 1.72.0 Includes using the right prototype for C SRepCatGetByShortname --- diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index 33fa83a92d..255fa1593c 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -44,7 +44,7 @@ impl StreamSlice { #[cfg(test)] pub fn from_slice(slice: &[u8], flags: u8, offset: u64) -> Self { Self { - input: slice.as_ptr() as *const u8, + input: slice.as_ptr(), input_len: slice.len() as u32, flags, offset diff --git a/rust/src/detect/byte_math.rs b/rust/src/detect/byte_math.rs index 0cc60e52bf..80bd3d5ee1 100644 --- a/rust/src/detect/byte_math.rs +++ b/rust/src/detect/byte_math.rs @@ -432,7 +432,7 @@ pub unsafe extern "C" fn ScByteMathParse(c_arg: *const c_char) -> *mut DetectByt } }; match parse_bytemath(arg) { - Ok((_, detect)) => return Box::into_raw(Box::new(detect)) as *mut DetectByteMathData, + Ok((_, detect)) => return Box::into_raw(Box::new(detect)), Err(_) => return std::ptr::null_mut(), } } @@ -440,7 +440,7 @@ pub unsafe extern "C" fn ScByteMathParse(c_arg: *const c_char) -> *mut DetectByt #[no_mangle] pub unsafe extern "C" fn ScByteMathFree(ptr: *mut DetectByteMathData) { if !ptr.is_null() { - let _ = Box::from_raw(ptr as *mut DetectByteMathData); + let _ = Box::from_raw(ptr); } } diff --git a/rust/src/detect/iprep.rs b/rust/src/detect/iprep.rs index 4018ea97a4..16f5d9d5d1 100644 --- a/rust/src/detect/iprep.rs +++ b/rust/src/detect/iprep.rs @@ -24,6 +24,7 @@ use nom7::Err; use nom7::IResult; use std::ffi::{CStr, CString}; +use std::os::raw::c_char; use std::str::FromStr; #[repr(u8)] @@ -71,7 +72,7 @@ pub fn is_alphanumeric_or_slash(chr: char) -> bool { } extern "C" { - pub fn SRepCatGetByShortname(name: *const i8) -> u8; + pub fn SRepCatGetByShortname(name: *const c_char) -> u8; } pub fn detect_parse_iprep(i: &str) -> IResult<&str, DetectIPRepData> { @@ -84,7 +85,7 @@ pub fn detect_parse_iprep(i: &str) -> IResult<&str, DetectIPRepData> { let (i, name) = take_while(is_alphanumeric_or_slash)(i)?; // copy as to have final zero let namez = CString::new(name).unwrap(); - let cat = unsafe { SRepCatGetByShortname(namez.as_ptr() as *const i8) }; + let cat = unsafe { SRepCatGetByShortname(namez.as_ptr()) }; if cat == 0 { return Err(Err::Error(make_error(i, ErrorKind::MapOpt))); } diff --git a/rust/src/ffi/base64.rs b/rust/src/ffi/base64.rs index 0019a6ff2b..ea72a344c3 100644 --- a/rust/src/ffi/base64.rs +++ b/rust/src/ffi/base64.rs @@ -46,7 +46,7 @@ pub unsafe extern "C" fn Base64Encode( if encoded.len() + 1 > *output_len as usize { return Base64ReturnCode::SC_BASE64_OVERFLOW; } - let output = std::slice::from_raw_parts_mut(&mut *(output as *mut u8), *output_len as usize); + let output = std::slice::from_raw_parts_mut(&mut *output, *output_len as usize); output[0..encoded.len()].copy_from_slice(encoded.as_bytes()); output[encoded.len()] = 0; *output_len = encoded.len() as c_ulong; diff --git a/rust/src/pgsql/parser.rs b/rust/src/pgsql/parser.rs index bb1a9ea09e..ae07d5d5a0 100644 --- a/rust/src/pgsql/parser.rs +++ b/rust/src/pgsql/parser.rs @@ -593,7 +593,7 @@ pub fn pgsql_parse_startup_packet(i: &[u8]) -> IResult<&[u8], PgsqlFEMessage> { let (i, b) = take(len - PGSQL_LENGTH_FIELD)(i)?; let (_, message) = match proto_major { - 1 | 2 | 3 => { + 1..=3 => { let (b, proto_major) = be_u16(b)?; let (b, proto_minor) = be_u16(b)?; let (b, params) = pgsql_parse_startup_parameters(b)?;