]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
rust(lint): don't use unwrap_or for function calls
authorJason Ish <jason.ish@oisf.net>
Fri, 20 Aug 2021 16:59:41 +0000 (10:59 -0600)
committerVictor Julien <victor@inliniac.net>
Mon, 23 Aug 2021 08:03:12 +0000 (10:03 +0200)
Calling a function in unwrap_or causes that function to always
be called even when not needed. Instead use unwrap_or_else with
a closure which will only be called when needed.

rust/src/dcerpc/dcerpc.rs
rust/src/smb/smb1_records.rs

index 3f00e8312b9b02079faf81645d9a4943db971048..45b68a66d0e707689b858bb217bdb556d3ba9e1c 100644 (file)
@@ -2149,7 +2149,7 @@ mod tests {
                     .zip(expected_uuid)
                     .map(|(x, y)| x.cmp(y))
                     .find(|&ord| ord != cmp::Ordering::Equal)
-                    .unwrap_or(bind_uuid.len().cmp(&expected_uuid.len()))
+                    .unwrap_or_else(|| bind_uuid.len().cmp(&expected_uuid.len()))
             );
         }
     }
index ec8f1f3052c228edc828916616d3794d1e689c4a..5bc886532b37ff7a6117b235c4cf02c94479b0bc 100644 (file)
@@ -582,7 +582,7 @@ pub fn parse_smb_create_andx_request_record<'a>(i: &'a[u8], r: &SmbRecord)
        >> (SmbRequestCreateAndXRecord {
                 disposition: disposition,
                 create_options: create_options,
-                file_name: file_name.unwrap_or(Vec::new()),
+                file_name: file_name.unwrap_or_default(),
            }))
 }