]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/clippy: fix lint: len_without_is_empty
authorJason Ish <jason.ish@oisf.net>
Tue, 29 Nov 2022 01:52:28 +0000 (19:52 -0600)
committerVictor Julien <vjulien@oisf.net>
Tue, 6 Dec 2022 13:10:11 +0000 (14:10 +0100)
rust/src/applayer.rs
rust/src/dcerpc/dcerpc.rs
rust/src/dns/dns.rs
rust/src/lib.rs
rust/src/pgsql/pgsql.rs

index 9a3687b56adfad1ffa3e927f6f69f5ab9719d681..e5be48944f1e0c1bc1d1d65ad42559b06ca10df4 100644 (file)
@@ -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
     }
index 5038e7b3c82f50ce3311b725ed226a97601e7de1..16227063731dc65b782816f1895d89772cd5f64a 100644 (file)
@@ -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. */
index c9eb443060ff99bf8ac49fbf60ad2b8a5f315f72..e2304e4ac6693208ff5934c5840d9e9e0c8bb758 100644 (file)
@@ -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()
index 137f97c2d13ad0edd1408b7e3e5bf37b80bfaac5..f8c4bf3fc8f38b77fd5e9c6fcd35a480652ffe93 100644 (file)
@@ -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)]
 
index 44118273730be28052098a2a96c93fe066a9a8d5..8db911330f3b392987cc0d88d5328ac86cc83044 100644 (file)
@@ -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()