From: Jason Ish Date: Mon, 3 Oct 2022 22:15:12 +0000 (-0600) Subject: rust/frames: cleanup clippy lint for unsafe X-Git-Tag: suricata-7.0.0-beta1~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9218da0eb82de672a4f61d6376509f32c336d973;p=thirdparty%2Fsuricata.git rust/frames: cleanup clippy lint for unsafe Where possible mark the relevant functions unsafe. Otherwise suppress the warning for now as this pattern is supposed to be a safe API around an unsafe one. Might need some further investigation, but in general the "guarantee" here is provided from the C side. --- diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index 3c493a44da..523c62a68f 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -662,18 +662,16 @@ pub trait AppLayerFrameType { fn to_cstring(&self) -> *const std::os::raw::c_char; /// Converts a C string formatted name to a frame type ID. - extern "C" fn ffi_id_from_name(name: *const std::os::raw::c_char) -> i32 where Self: Sized { + unsafe extern "C" fn ffi_id_from_name(name: *const std::os::raw::c_char) -> i32 where Self: Sized { if name.is_null() { return -1; } - unsafe { - let frame_id = if let Ok(s) = std::ffi::CStr::from_ptr(name).to_str() { - Self::from_str(s).map(|t| t.as_u8() as i32).unwrap_or(-1) - } else { - -1 - }; - frame_id - } + let frame_id = if let Ok(s) = std::ffi::CStr::from_ptr(name).to_str() { + Self::from_str(s).map(|t| t.as_u8() as i32).unwrap_or(-1) + } else { + -1 + }; + frame_id } /// Converts a variant ID to an FFI safe name. diff --git a/rust/src/frames.rs b/rust/src/frames.rs index 3f1953d5d2..aa6bf4375f 100644 --- a/rust/src/frames.rs +++ b/rust/src/frames.rs @@ -49,6 +49,7 @@ impl std::fmt::Debug for Frame { } impl Frame { + #[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn new( flow: *const Flow, stream_slice: &StreamSlice, frame_start: &[u8], frame_len: i64, frame_type: u8, @@ -92,18 +93,21 @@ impl Frame { } } + #[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn set_len(&self, flow: *const Flow, len: i64) { unsafe { AppLayerFrameSetLengthById(flow, self.direction(), self.id, len); }; } + #[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn set_tx(&self, flow: *const Flow, tx_id: u64) { unsafe { AppLayerFrameSetTxIdById(flow, self.direction(), self.id, tx_id); }; } + #[allow(clippy::not_unsafe_ptr_arg_deref)] pub fn add_event(&self, flow: *const Flow, event: u8) { unsafe { AppLayerFrameAddEventById(flow, self.direction(), self.id, event);