From: Jason Ish Date: Tue, 29 Nov 2022 01:52:28 +0000 (-0600) Subject: rust/clippy: fix lint: len_without_is_empty X-Git-Tag: suricata-7.0.0-rc1~280 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4940dfb3bda52d53e1c8fa29b7f0493295bc6784;p=thirdparty%2Fsuricata.git rust/clippy: fix lint: len_without_is_empty --- diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index 9a3687b56a..e5be48944f 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -59,6 +59,9 @@ impl StreamSlice { pub fn as_slice(&self) -> &[u8] { unsafe { std::slice::from_raw_parts(self.input, self.input_len as usize) } } + pub fn is_empty(&self) -> bool { + self.input_len == 0 + } pub fn len(&self) -> u32 { self.input_len } diff --git a/rust/src/dcerpc/dcerpc.rs b/rust/src/dcerpc/dcerpc.rs index 5038e7b3c8..1622706373 100644 --- a/rust/src/dcerpc/dcerpc.rs +++ b/rust/src/dcerpc/dcerpc.rs @@ -1137,7 +1137,7 @@ pub unsafe extern "C" fn rs_dcerpc_parse_request( SCLogDebug!("Handling request: input_len {} flags {:x} EOF {}", stream_slice.len(), flags, flags & core::STREAM_EOF != 0); - if flags & core::STREAM_EOF != 0 && stream_slice.len() == 0 { + if flags & core::STREAM_EOF != 0 && stream_slice.is_empty() { return AppLayerResult::ok(); } /* START with MIDSTREAM set: record might be starting the middle. */ @@ -1160,7 +1160,7 @@ pub unsafe extern "C" fn rs_dcerpc_parse_response( let state = cast_pointer!(state, DCERPCState); let flags = stream_slice.flags(); - if flags & core::STREAM_EOF != 0 && stream_slice.len() == 0 { + if flags & core::STREAM_EOF != 0 && stream_slice.is_empty() { return AppLayerResult::ok(); } /* START with MIDSTREAM set: record might be starting the middle. */ diff --git a/rust/src/dns/dns.rs b/rust/src/dns/dns.rs index c9eb443060..e2304e4ac6 100644 --- a/rust/src/dns/dns.rs +++ b/rust/src/dns/dns.rs @@ -740,7 +740,7 @@ pub unsafe extern "C" fn rs_dns_parse_request_tcp(flow: *const core::Flow, let state = cast_pointer!(state, DNSState); if stream_slice.is_gap() { state.request_gap(stream_slice.gap_size()); - } else if stream_slice.len() > 0 { + } else if !stream_slice.is_empty() { return state.parse_request_tcp(flow, stream_slice); } AppLayerResult::ok() @@ -757,7 +757,7 @@ pub unsafe extern "C" fn rs_dns_parse_response_tcp(flow: *const core::Flow, let state = cast_pointer!(state, DNSState); if stream_slice.is_gap() { state.response_gap(stream_slice.gap_size()); - } else if stream_slice.len() > 0 { + } else if !stream_slice.is_empty() { return state.parse_response_tcp(flow, stream_slice); } AppLayerResult::ok() diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 137f97c2d1..f8c4bf3fc8 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -23,7 +23,6 @@ // Clippy lints we want to suppress due to style, or simply too noisy // and not a priority right now. -#![allow(clippy::len_without_is_empty)] #![allow(clippy::missing_safety_doc)] #![allow(clippy::too_many_arguments)] diff --git a/rust/src/pgsql/pgsql.rs b/rust/src/pgsql/pgsql.rs index 4411827373..8db911330f 100644 --- a/rust/src/pgsql/pgsql.rs +++ b/rust/src/pgsql/pgsql.rs @@ -628,7 +628,7 @@ pub unsafe extern "C" fn rs_pgsql_parse_request( _flow: *const Flow, state: *mut std::os::raw::c_void, pstate: *mut std::os::raw::c_void, stream_slice: StreamSlice, _data: *const std::os::raw::c_void, ) -> AppLayerResult { - if stream_slice.len() == 0 { + if stream_slice.is_empty() { if AppLayerParserStateIssetFlag(pstate, APP_LAYER_PARSER_EOF_TS) > 0 { SCLogDebug!(" Suricata reached `eof`"); return AppLayerResult::ok(); @@ -642,7 +642,7 @@ pub unsafe extern "C" fn rs_pgsql_parse_request( if stream_slice.is_gap() { state_safe.on_request_gap(stream_slice.gap_size()); - } else if stream_slice.len() > 0 { + } else if !stream_slice.is_empty() { return state_safe.parse_request(stream_slice.as_slice()); } AppLayerResult::ok() @@ -659,7 +659,7 @@ pub unsafe extern "C" fn rs_pgsql_parse_response( if stream_slice.is_gap() { state_safe.on_response_gap(stream_slice.gap_size()); - } else if stream_slice.len() > 0 { + } else if !stream_slice.is_empty() { return state_safe.parse_response(stream_slice.as_slice(), flow); } AppLayerResult::ok()