From a3b22acb0430886a70a5d809a2da9d0a700f1510 Mon Sep 17 00:00:00 2001 From: Dominik Maier Date: Tue, 2 Mar 2021 20:44:17 +0100 Subject: [PATCH] clippy --- libafl/src/bolts/llmp.rs | 16 ++++++++-------- libafl/src/corpus/ondisk.rs | 2 +- libafl/src/events/llmp.rs | 17 +++++++---------- libafl/src/mutators/mutations.rs | 10 ++-------- libafl/src/mutators/scheduled.rs | 11 +++++++++++ libafl/src/mutators/token_mutations.rs | 2 +- 6 files changed, 30 insertions(+), 28 deletions(-) diff --git a/libafl/src/bolts/llmp.rs b/libafl/src/bolts/llmp.rs index 95afb6f9f4..1daf42db52 100644 --- a/libafl/src/bolts/llmp.rs +++ b/libafl/src/bolts/llmp.rs @@ -1232,10 +1232,9 @@ where .expect("An error occurred when brokering. Exiting."); #[cfg(feature = "std")] - match sleep_time { - Some(time) => thread::sleep(time), - None => (), - } + if let Some(time) = sleep_time { + thread::sleep(time) + }; #[cfg(not(feature = "std"))] match sleep_time { @@ -1407,10 +1406,9 @@ where let map = &mut self.llmp_clients[client_id as usize].current_recv_map; let msg_buf = (*msg).as_slice(map)?; - match (on_new_msg)(client_id, (*msg).tag, msg_buf)? { - LlmpMsgHookResult::Handled => should_forward_msg = false, - _ => (), - } + if let LlmpMsgHookResult::Handled = (on_new_msg)(client_id, (*msg).tag, msg_buf)? { + should_forward_msg = false + }; if should_forward_msg { self.forward_msg(msg)?; } @@ -1574,6 +1572,8 @@ where /// The current page could have changed in recv (EOP) /// Alloc the next message, internally handling end of page by allocating a new one. + /// # Safety + /// Should be safe, but returns an unsafe ptr #[inline] pub unsafe fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, Error> { self.sender.alloc_next(buf_len) diff --git a/libafl/src/corpus/ondisk.rs b/libafl/src/corpus/ondisk.rs index dafe3ecc5a..f9ca34d1e4 100644 --- a/libafl/src/corpus/ondisk.rs +++ b/libafl/src/corpus/ondisk.rs @@ -35,7 +35,7 @@ where /// Add an entry to the corpus and return its index #[inline] fn add(&mut self, mut testcase: Testcase) -> Result { - if let None = testcase.filename() { + if testcase.filename().is_none() { // TODO walk entry metadata to ask for pices of filename (e.g. :havoc in AFL) let filename = self.dir_path.join(format!("id_{}", &self.entries.len())); let filename_str = filename.to_str().expect("Invalid Path"); diff --git a/libafl/src/events/llmp.rs b/libafl/src/events/llmp.rs index 543a460aa1..cf8a2ad993 100644 --- a/libafl/src/events/llmp.rs +++ b/libafl/src/events/llmp.rs @@ -328,18 +328,15 @@ where // TODO: Get around local event copy by moving handle_in_client let mut events = vec![]; match &mut self.llmp { - llmp::LlmpConnection::IsClient { client } => loop { - match client.recv_buf()? { - Some((sender_id, tag, msg)) => { - if tag == _LLMP_TAG_EVENT_TO_BROKER { - continue; - } - let event: Event = postcard::from_bytes(msg)?; - events.push((sender_id, event)); + llmp::LlmpConnection::IsClient { client } => { + while let Some((sender_id, tag, msg)) = client.recv_buf()? { + if tag == _LLMP_TAG_EVENT_TO_BROKER { + continue; } - None => break, + let event: Event = postcard::from_bytes(msg)?; + events.push((sender_id, event)); } - }, + } _ => { #[cfg(feature = "std")] dbg!("Skipping process in broker"); diff --git a/libafl/src/mutators/mutations.rs b/libafl/src/mutators/mutations.rs index 3a0dfebbe8..dd8946eec9 100644 --- a/libafl/src/mutators/mutations.rs +++ b/libafl/src/mutators/mutations.rs @@ -46,7 +46,7 @@ pub fn buffer_self_copy(data: &mut [u8], from: usize, to: usize, len: usize) { debug_assert!(to + len <= data.len()); if len != 0 && from != to { let ptr = data.as_mut_ptr(); - unsafe { core::ptr::copy(ptr.offset(from as isize), ptr.offset(to as isize), len) } + unsafe { core::ptr::copy(ptr.add(from), ptr.add(to), len) } } } @@ -60,13 +60,7 @@ pub fn buffer_copy(dst: &mut [u8], src: &[u8], from: usize, to: usize, len: usiz let dst_ptr = dst.as_mut_ptr(); let src_ptr = src.as_ptr(); if len != 0 { - unsafe { - core::ptr::copy( - src_ptr.offset(from as isize), - dst_ptr.offset(to as isize), - len, - ) - } + unsafe { core::ptr::copy(src_ptr.add(from), dst_ptr.add(to), len) } } } diff --git a/libafl/src/mutators/scheduled.rs b/libafl/src/mutators/scheduled.rs index 8fad11a207..20922dee24 100644 --- a/libafl/src/mutators/scheduled.rs +++ b/libafl/src/mutators/scheduled.rs @@ -139,6 +139,17 @@ where } } +impl Default for StdScheduledMutator +where + I: Input, + S: HasRand, + R: Rand, +{ + fn default() -> Self { + Self::new() + } +} + /// Schedule some selected byte level mutations given a ScheduledMutator type #[derive(Clone, Debug)] pub struct HavocBytesMutator diff --git a/libafl/src/mutators/token_mutations.rs b/libafl/src/mutators/token_mutations.rs index c722e25e18..90741b2f97 100644 --- a/libafl/src/mutators/token_mutations.rs +++ b/libafl/src/mutators/token_mutations.rs @@ -75,7 +75,7 @@ impl Tokens { let line = line.trim_start().trim_end(); // we are only interested in '"..."', not prefixed 'foo = ' - let start = line.chars().nth(0); + let start = line.chars().next(); if line.is_empty() || start == Some('#') { continue; }