some clippy fixes

This commit is contained in:
Dominik Maier 2021-03-02 19:33:03 +01:00
parent 706d5c710d
commit dbd3cbd99c
20 changed files with 161 additions and 128 deletions

View File

@ -71,7 +71,6 @@ macro_rules! create_serde_registry_for_trait {
pub mod $mod_name { pub mod $mod_name {
use alloc::boxed::Box; use alloc::boxed::Box;
use alloc::string::String;
use core::any::{Any, TypeId}; use core::any::{Any, TypeId};
use core::fmt; use core::fmt;
use postcard; use postcard;
@ -260,7 +259,7 @@ macro_rules! create_serde_registry_for_trait {
impl NamedSerdeAnyMap { impl NamedSerdeAnyMap {
#[inline] #[inline]
pub fn get<T>(&self, name: &String) -> Option<&T> pub fn get<T>(&self, name: &str) -> Option<&T>
where where
T: Any, T: Any,
{ {
@ -273,11 +272,7 @@ macro_rules! create_serde_registry_for_trait {
} }
#[inline] #[inline]
pub fn by_typeid( pub fn by_typeid(&self, name: &str, typeid: &TypeId) -> Option<&dyn $trait_name> {
&self,
name: &String,
typeid: &TypeId,
) -> Option<&dyn $trait_name> {
match self.map.get(&unpack_type_id(*typeid)) { match self.map.get(&unpack_type_id(*typeid)) {
None => None, None => None,
Some(h) => h Some(h) => h
@ -287,7 +282,7 @@ macro_rules! create_serde_registry_for_trait {
} }
#[inline] #[inline]
pub fn get_mut<T>(&mut self, name: &String) -> Option<&mut T> pub fn get_mut<T>(&mut self, name: &str) -> Option<&mut T>
where where
T: Any, T: Any,
{ {
@ -302,7 +297,7 @@ macro_rules! create_serde_registry_for_trait {
#[inline] #[inline]
pub fn by_typeid_mut( pub fn by_typeid_mut(
&mut self, &mut self,
name: &String, name: &str,
typeid: &TypeId, typeid: &TypeId,
) -> Option<&mut dyn $trait_name> { ) -> Option<&mut dyn $trait_name> {
match self.map.get_mut(&unpack_type_id(*typeid)) { match self.map.get_mut(&unpack_type_id(*typeid)) {
@ -423,7 +418,7 @@ macro_rules! create_serde_registry_for_trait {
} }
#[inline] #[inline]
pub fn insert(&mut self, val: Box<dyn $trait_name>, name: &String) { pub fn insert(&mut self, val: Box<dyn $trait_name>, name: &str) {
let id = unpack_type_id((*val).type_id()); let id = unpack_type_id((*val).type_id());
if !self.map.contains_key(&id) { if !self.map.contains_key(&id) {
self.map.insert(id, HashMap::default()); self.map.insert(id, HashMap::default());
@ -448,7 +443,7 @@ macro_rules! create_serde_registry_for_trait {
} }
#[inline] #[inline]
pub fn contains<T>(&self, name: &String) -> bool pub fn contains<T>(&self, name: &str) -> bool
where where
T: Any, T: Any,
{ {

View File

@ -71,7 +71,7 @@ pub trait ShMem: Sized + Debug {
fn description(&self) -> ShMemDescription { fn description(&self) -> ShMemDescription {
ShMemDescription { ShMemDescription {
size: self.map().len(), size: self.map().len(),
str_bytes: self.shm_slice().clone(), str_bytes: *self.shm_slice(),
} }
} }
@ -103,7 +103,7 @@ pub trait ShMem: Sized + Debug {
#[cfg(feature = "std")] #[cfg(feature = "std")]
pub mod shmem { pub mod shmem {
use core::{mem::size_of, slice}; use core::{mem::size_of, ptr, slice};
use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_ushort, c_void}; use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_ushort, c_void};
use std::ffi::CStr; use std::ffi::CStr;
@ -222,7 +222,7 @@ pub mod shmem {
pub fn from_str(shm_str: &CStr, map_size: usize) -> Result<Self, Error> { pub fn from_str(shm_str: &CStr, map_size: usize) -> Result<Self, Error> {
let mut ret = afl_shmem_unitialized(); let mut ret = afl_shmem_unitialized();
let map = unsafe { afl_shmem_by_str(&mut ret, shm_str, map_size) }; let map = unsafe { afl_shmem_by_str(&mut ret, shm_str, map_size) };
if map != 0 as *mut u8 { if !map.is_null() {
Ok(ret) Ok(ret)
} else { } else {
Err(Error::Unknown(format!( Err(Error::Unknown(format!(
@ -235,7 +235,7 @@ pub mod shmem {
pub fn new(map_size: usize) -> Result<Self, Error> { pub fn new(map_size: usize) -> Result<Self, Error> {
let mut ret = afl_shmem_unitialized(); let mut ret = afl_shmem_unitialized();
let map = unsafe { afl_shmem_init(&mut ret, map_size) }; let map = unsafe { afl_shmem_init(&mut ret, map_size) };
if map != 0 as *mut u8 { if !map.is_null() {
Ok(ret) Ok(ret)
} else { } else {
Err(Error::Unknown(format!( Err(Error::Unknown(format!(
@ -253,24 +253,24 @@ pub mod shmem {
// Not set or not initialized; // Not set or not initialized;
return; return;
} }
(*shm).shm_str[0 as usize] = '\u{0}' as u8; (*shm).shm_str[0 as usize] = 0u8;
shmctl((*shm).shm_id, 0 as c_int, 0 as *mut shmid_ds); shmctl((*shm).shm_id, 0 as c_int, ptr::null_mut());
(*shm).map = 0 as *mut c_uchar; (*shm).map = ptr::null_mut();
} }
/// Functions to create Shared memory region, for observation channels and /// Functions to create Shared memory region, for observation channels and
/// opening inputs and stuff. /// opening inputs and stuff.
unsafe fn afl_shmem_init(shm: *mut UnixShMem, map_size: usize) -> *mut c_uchar { unsafe fn afl_shmem_init(shm: *mut UnixShMem, map_size: usize) -> *mut c_uchar {
(*shm).map_size = map_size; (*shm).map_size = map_size;
(*shm).map = 0 as *mut c_uchar; (*shm).map = ptr::null_mut();
(*shm).shm_id = shmget( (*shm).shm_id = shmget(
0 as c_int, 0 as c_int,
map_size as c_ulong, map_size as c_ulong,
0o1000 as c_int | 0o2000 as c_int | 0o600 as c_int, 0o1000 as c_int | 0o2000 as c_int | 0o600 as c_int,
); );
if (*shm).shm_id < 0 as c_int { if (*shm).shm_id < 0 as c_int {
(*shm).shm_str[0] = '\u{0}' as u8; (*shm).shm_str[0] = 0u8;
return 0 as *mut c_uchar; return ptr::null_mut();
} }
snprintf( snprintf(
(*shm).shm_str.as_mut_ptr() as *mut c_char, (*shm).shm_str.as_mut_ptr() as *mut c_char,
@ -280,13 +280,13 @@ pub mod shmem {
); );
(*shm).shm_str (*shm).shm_str
[(size_of::<[c_char; 20]>() as c_ulong).wrapping_sub(1 as c_int as c_ulong) as usize] = [(size_of::<[c_char; 20]>() as c_ulong).wrapping_sub(1 as c_int as c_ulong) as usize] =
'\u{0}' as u8; 0u8;
(*shm).map = shmat((*shm).shm_id, 0 as *const c_void, 0 as c_int) as *mut c_uchar; (*shm).map = shmat((*shm).shm_id, ptr::null(), 0 as c_int) as *mut c_uchar;
if (*shm).map == -(1 as c_int) as *mut c_void as *mut c_uchar || (*shm).map.is_null() { if (*shm).map == -(1 as c_int) as *mut c_void as *mut c_uchar || (*shm).map.is_null() {
shmctl((*shm).shm_id, 0 as c_int, 0 as *mut shmid_ds); shmctl((*shm).shm_id, 0 as c_int, ptr::null_mut());
(*shm).shm_id = -(1 as c_int); (*shm).shm_id = -(1 as c_int);
(*shm).shm_str[0 as c_int as usize] = '\u{0}' as u8; (*shm).shm_str[0 as c_int as usize] = 0u8;
return 0 as *mut c_uchar; return ptr::null_mut();
} }
return (*shm).map; return (*shm).map;
} }
@ -297,10 +297,10 @@ pub mod shmem {
shm_str: &CStr, shm_str: &CStr,
map_size: usize, map_size: usize,
) -> *mut c_uchar { ) -> *mut c_uchar {
if shm.is_null() || shm_str.to_bytes().len() == 0 || map_size == 0 { if shm.is_null() || shm_str.to_bytes().is_empty() || map_size == 0 {
return 0 as *mut c_uchar; return ptr::null_mut();
} }
(*shm).map = 0 as *mut c_uchar; (*shm).map = ptr::null_mut();
(*shm).map_size = map_size; (*shm).map_size = map_size;
strncpy( strncpy(
(*shm).shm_str.as_mut_ptr() as *mut c_char, (*shm).shm_str.as_mut_ptr() as *mut c_char,
@ -312,12 +312,12 @@ pub mod shmem {
.expect(&format!("illegal shm_str {:?}", shm_str)) .expect(&format!("illegal shm_str {:?}", shm_str))
.parse::<i32>() .parse::<i32>()
.unwrap(); .unwrap();
(*shm).map = shmat((*shm).shm_id, 0 as *const c_void, 0 as c_int) as *mut c_uchar; (*shm).map = shmat((*shm).shm_id, ptr::null(), 0 as c_int) as *mut c_uchar;
if (*shm).map == -(1 as c_int) as *mut c_void as *mut c_uchar { if (*shm).map == -(1 as c_int) as *mut c_void as *mut c_uchar {
(*shm).map = 0 as *mut c_uchar; (*shm).map = ptr::null_mut();
(*shm).map_size = 0; (*shm).map_size = 0;
(*shm).shm_str[0] = '\u{0}' as u8; (*shm).shm_str[0] = 0u8;
return 0 as *mut c_uchar; return ptr::null_mut();
} }
return (*shm).map; return (*shm).map;
} }

View File

@ -6,6 +6,9 @@ use core::any::TypeId;
pub trait HasLen { pub trait HasLen {
fn len(&self) -> usize; fn len(&self) -> usize;
fn is_empty(&self) -> bool {
self.len() == 0
}
} }
impl HasLen for () { impl HasLen for () {

View File

@ -37,6 +37,12 @@ impl TopRatedsMetadata {
} }
} }
impl Default for TopRatedsMetadata {
fn default() -> Self {
Self::new()
}
}
pub trait FavFactor<I> pub trait FavFactor<I>
where where
I: Input, I: Input,

View File

@ -128,6 +128,7 @@ where
I: Input, I: Input,
R: Rand, R: Rand,
{ {
/// Create a new RandCorpusScheduler that just schedules randomly.
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
phantom: PhantomData, phantom: PhantomData,
@ -135,4 +136,16 @@ where
} }
} }
impl<C, I, R, S> Default for RandCorpusScheduler<C, I, R, S>
where
S: HasCorpus<C, I> + HasRand<R>,
C: Corpus<I>,
I: Input,
R: Rand,
{
fn default() -> Self {
Self::new()
}
}
pub type StdCorpusScheduler<C, I, R, S> = RandCorpusScheduler<C, I, R, S>; pub type StdCorpusScheduler<C, I, R, S> = RandCorpusScheduler<C, I, R, S>;

View File

@ -35,18 +35,15 @@ where
/// Add an entry to the corpus and return its index /// Add an entry to the corpus and return its index
#[inline] #[inline]
fn add(&mut self, mut testcase: Testcase<I>) -> Result<usize, Error> { fn add(&mut self, mut testcase: Testcase<I>) -> Result<usize, Error> {
match testcase.filename() { if let None = testcase.filename() {
None => { // TODO walk entry metadata to ask for pices of filename (e.g. :havoc in AFL)
// 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 = self.dir_path.join(format!("id_{}", &self.entries.len())); let filename_str = filename.to_str().expect("Invalid Path");
let filename_str = filename.to_str().expect("Invalid Path"); testcase.set_filename(filename_str.into());
testcase.set_filename(filename_str.into()); };
}
_ => {}
}
testcase testcase
.store_input() .store_input()
.expect("Could not save testcase to disk".into()); .expect("Could not save testcase to disk");
self.entries.push(RefCell::new(testcase)); self.entries.push(RefCell::new(testcase));
Ok(self.entries.len() - 1) Ok(self.entries.len() - 1)
} }

View File

@ -59,6 +59,17 @@ where
} }
} }
impl<C, I, S> Default for QueueCorpusScheduler<C, I, S>
where
S: HasCorpus<C, I>,
C: Corpus<I>,
I: Input,
{
fn default() -> Self {
Self::new()
}
}
/* /*
#[cfg(test)] #[cfg(test)]
#[cfg(feature = "std")] #[cfg(feature = "std")]

View File

@ -181,7 +181,7 @@ where
#[inline] #[inline]
pub fn with_fitness(input: I, fitness: u32) -> Self { pub fn with_fitness(input: I, fitness: u32) -> Self {
Testcase { Testcase {
input: Some(input.into()), input: Some(input),
filename: None, filename: None,
fitness: fitness, fitness: fitness,
metadata: SerdeAnyMap::new(), metadata: SerdeAnyMap::new(),

View File

@ -167,10 +167,7 @@ where
/// Returns if we are the broker /// Returns if we are the broker
pub fn is_broker(&self) -> bool { pub fn is_broker(&self) -> bool {
match self.llmp { matches!(self.llmp, llmp::LlmpConnection::IsBroker { broker: _ })
llmp::LlmpConnection::IsBroker { broker: _ } => true,
_ => false,
}
} }
/// Run forever in the broker /// Run forever in the broker
@ -284,9 +281,9 @@ where
// TODO include ExitKind in NewTestcase // TODO include ExitKind in NewTestcase
let fitness = state.is_interesting(&input, &observers, ExitKind::Ok)?; let fitness = state.is_interesting(&input, &observers, ExitKind::Ok)?;
if fitness > 0 { if fitness > 0 {
if !state if state
.add_if_interesting(&input, fitness, scheduler)? .add_if_interesting(&input, fitness, scheduler)?
.is_none() .is_some()
{ {
#[cfg(feature = "std")] #[cfg(feature = "std")]
println!("Added received Testcase"); println!("Added received Testcase");
@ -312,12 +309,9 @@ where
/// The llmp client needs to wait until a broker mapped all pages, before shutting down. /// The llmp client needs to wait until a broker mapped all pages, before shutting down.
/// Otherwise, the OS may already have removed the shared maps, /// Otherwise, the OS may already have removed the shared maps,
fn await_restart_safe(&mut self) { fn await_restart_safe(&mut self) {
match &self.llmp { if let llmp::LlmpConnection::IsClient { client } = &self.llmp {
llmp::LlmpConnection::IsClient { client } => { // wait until we can drop the message safely.
// wait until we can drop the message safely. client.await_save_to_unmap_blocking();
client.await_save_to_unmap_blocking();
}
_ => (),
} }
} }

View File

@ -43,7 +43,7 @@ where
OT: ObserversTuple, OT: ObserversTuple,
{ {
let count = self.events.len(); let count = self.events.len();
while self.events.len() > 0 { while !self.events.is_empty() {
let event = self.events.pop().unwrap(); let event = self.events.pop().unwrap();
self.handle_in_client(state, event)?; self.handle_in_client(state, event)?;
} }
@ -118,11 +118,9 @@ where
// Handle arriving events in the client // Handle arriving events in the client
fn handle_in_client(&mut self, _state: &mut S, event: Event<I>) -> Result<(), Error> { fn handle_in_client(&mut self, _state: &mut S, event: Event<I>) -> Result<(), Error> {
match event { Err(Error::Unknown(format!(
_ => Err(Error::Unknown(format!( "Received illegal message that message should not have arrived: {:?}.",
"Received illegal message that message should not have arrived: {:?}.", event
event )))
))),
}
} }
} }

View File

@ -77,9 +77,7 @@ where
{ {
#[cfg(unix)] #[cfg(unix)]
#[cfg(feature = "std")] #[cfg(feature = "std")]
unsafe { reset_oncrash_ptrs();
reset_oncrash_ptrs();
}
Ok(()) Ok(())
} }
@ -206,7 +204,7 @@ pub mod unix_signals {
S: HasObjectives<OFT, I> + HasSolutions<OC, I>, S: HasObjectives<OFT, I> + HasSolutions<OC, I>,
I: Input, I: Input,
{ {
if CURRENT_INPUT_PTR == ptr::null() { if CURRENT_INPUT_PTR.is_null() {
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
let si_addr = { ((info._pad[0] as usize) | ((info._pad[1] as usize) << 32)) as usize }; let si_addr = { ((info._pad[0] as usize) | ((info._pad[1] as usize) << 32)) as usize };
#[cfg(not(target_os = "android"))] #[cfg(not(target_os = "android"))]
@ -250,19 +248,19 @@ pub mod unix_signals {
let obj_fitness = state let obj_fitness = state
.objectives_mut() .objectives_mut()
.is_interesting_all(&input, observers, ExitKind::Crash) .is_interesting_all(&input, observers, ExitKind::Crash)
.expect("In crash handler objectives failure.".into()); .expect("In crash handler objectives failure.");
if obj_fitness > 0 { if obj_fitness > 0 {
state state
.solutions_mut() .solutions_mut()
.add(Testcase::new(input.clone())) .add(Testcase::new(input.clone()))
.expect("In crash handler solutions failure.".into()); .expect("In crash handler solutions failure.");
mgr.fire( mgr.fire(
state, state,
Event::Objective { Event::Objective {
objective_size: state.solutions().count(), objective_size: state.solutions().count(),
}, },
) )
.expect("Could not send crashing input".into()); .expect("Could not send crashing input");
} }
mgr.on_restart(state).unwrap(); mgr.on_restart(state).unwrap();
@ -305,19 +303,19 @@ pub mod unix_signals {
let obj_fitness = state let obj_fitness = state
.objectives_mut() .objectives_mut()
.is_interesting_all(&input, observers, ExitKind::Crash) .is_interesting_all(&input, observers, ExitKind::Crash)
.expect("In timeout handler objectives failure.".into()); .expect("In timeout handler objectives failure.");
if obj_fitness > 0 { if obj_fitness > 0 {
state state
.solutions_mut() .solutions_mut()
.add(Testcase::new(input.clone())) .add(Testcase::new(input.clone()))
.expect("In timeout handler solutions failure.".into()); .expect("In timeout handler solutions failure.");
mgr.fire( mgr.fire(
state, state,
Event::Objective { Event::Objective {
objective_size: state.solutions().count(), objective_size: state.solutions().count(),
}, },
) )
.expect("Could not send timeouting input".into()); .expect("Could not send timeouting input");
} }
mgr.on_restart(state).unwrap(); mgr.on_restart(state).unwrap();
@ -331,6 +329,10 @@ pub mod unix_signals {
std::process::exit(1); std::process::exit(1);
} }
/// Sets the oncrash pointers before executing a single testcase
/// # Safety
/// As long as no signals are called, this is fine.
/// Once a signal occurs, the pointer needs to be up to date.
#[inline] #[inline]
pub unsafe fn set_oncrash_ptrs<EM, I, OT, S>( pub unsafe fn set_oncrash_ptrs<EM, I, OT, S>(
state: &mut S, state: &mut S,
@ -344,14 +346,20 @@ pub mod unix_signals {
OBSERVERS_PTR = observers as *const _ as *const c_void; OBSERVERS_PTR = observers as *const _ as *const c_void;
} }
/// Resets the oncrash pointers to null
#[inline] #[inline]
pub unsafe fn reset_oncrash_ptrs() { pub fn reset_oncrash_ptrs() {
CURRENT_INPUT_PTR = ptr::null(); unsafe {
STATE_PTR = ptr::null_mut(); CURRENT_INPUT_PTR = ptr::null();
EVENT_MGR_PTR = ptr::null_mut(); STATE_PTR = ptr::null_mut();
OBSERVERS_PTR = ptr::null(); EVENT_MGR_PTR = ptr::null_mut();
OBSERVERS_PTR = ptr::null();
}
} }
/// Sets up the crash handler
/// # Safety
/// Everything using signals is unsafe. Don't do it unless you really need to.
pub unsafe fn setup_crash_handlers<EM, I, OC, OFT, OT, S>() pub unsafe fn setup_crash_handlers<EM, I, OC, OFT, OT, S>()
where where
EM: EventManager<I, S>, EM: EventManager<I, S>,

View File

@ -59,7 +59,7 @@ where
I: Input + HasTargetBytes, I: Input + HasTargetBytes,
{ {
fn run_target(&mut self, input: &I) -> Result<ExitKind, Error> { fn run_target(&mut self, input: &I) -> Result<ExitKind, Error> {
if input.target_bytes().as_slice().len() == 0 { if input.target_bytes().as_slice().is_empty() {
Err(Error::Empty("Input Empty".into())) Err(Error::Empty("Input Empty".into()))
} else { } else {
Ok(ExitKind::Ok) Ok(ExitKind::Ok)

View File

@ -218,19 +218,13 @@ where
} }
fn append_metadata(&mut self, testcase: &mut Testcase<I>) -> Result<(), Error> { fn append_metadata(&mut self, testcase: &mut Testcase<I>) -> Result<(), Error> {
match self.indexes.as_mut() { if let Some(v) = self.indexes.as_mut() {
Some(v) => { let meta = MapIndexesMetadata::new(core::mem::take(v));
let meta = MapIndexesMetadata::new(core::mem::take(v)); testcase.add_metadata(meta);
testcase.add_metadata(meta);
}
None => {}
}; };
match self.novelties.as_mut() { if let Some(v) = self.novelties.as_mut() {
Some(v) => { let meta = MapNoveltiesMetadata::new(core::mem::take(v));
let meta = MapNoveltiesMetadata::new(core::mem::take(v)); testcase.add_metadata(meta);
testcase.add_metadata(meta);
}
None => {}
}; };
Ok(()) Ok(())
} }

View File

@ -184,3 +184,9 @@ impl CrashFeedback {
Self {} Self {}
} }
} }
impl Default for CrashFeedback {
fn default() -> Self {
Self::new()
}
}

View File

@ -93,7 +93,7 @@ where
/// Generates up to DUMMY_BYTES_MAX non-random dummy bytes (0) /// Generates up to DUMMY_BYTES_MAX non-random dummy bytes (0)
fn generate_dummy(&self) -> BytesInput { fn generate_dummy(&self) -> BytesInput {
let size = min(self.max_size, DUMMY_BYTES_MAX); let size = min(self.max_size, DUMMY_BYTES_MAX);
BytesInput::new(vec!['0' as u8; size]) BytesInput::new(vec![0u8; size])
} }
} }

View File

@ -97,6 +97,10 @@ pub trait HasBytesVec {
/// Has a length field /// Has a length field
pub trait HasLen { pub trait HasLen {
/// The lenght /// The length
fn len(&self) -> usize; fn len(&self) -> usize;
fn is_empty(&self) -> bool {
self.len() == 0
}
} }

View File

@ -41,7 +41,7 @@ where
/// Mem move in the own vec /// Mem move in the own vec
#[inline] #[inline]
pub fn buffer_self_copy(data: &mut [u8], from: usize, to: usize, len: usize) { pub fn buffer_self_copy(data: &mut [u8], from: usize, to: usize, len: usize) {
debug_assert!(data.len() > 0); debug_assert!(!data.is_empty());
debug_assert!(from + len <= data.len()); debug_assert!(from + len <= data.len());
debug_assert!(to + len <= data.len()); debug_assert!(to + len <= data.len());
if len != 0 && from != to { if len != 0 && from != to {
@ -53,8 +53,8 @@ pub fn buffer_self_copy(data: &mut [u8], from: usize, to: usize, len: usize) {
/// Mem move between vecs /// Mem move between vecs
#[inline] #[inline]
pub fn buffer_copy(dst: &mut [u8], src: &[u8], from: usize, to: usize, len: usize) { pub fn buffer_copy(dst: &mut [u8], src: &[u8], from: usize, to: usize, len: usize) {
debug_assert!(dst.len() > 0); debug_assert!(!dst.is_empty());
debug_assert!(src.len() > 0); debug_assert!(!src.is_empty());
debug_assert!(from + len <= src.len()); debug_assert!(from + len <= src.len());
debug_assert!(to + len <= dst.len()); debug_assert!(to + len <= dst.len());
let dst_ptr = dst.as_mut_ptr(); let dst_ptr = dst.as_mut_ptr();
@ -124,7 +124,7 @@ where
S: HasRand<R> + HasMaxSize, S: HasRand<R> + HasMaxSize,
R: Rand, R: Rand,
{ {
if input.bytes().len() == 0 { if input.bytes().is_empty() {
Ok(MutationResult::Skipped) Ok(MutationResult::Skipped)
} else { } else {
let bit = state.rand_mut().below((input.bytes().len() << 3) as u64) as usize; let bit = state.rand_mut().below((input.bytes().len() << 3) as u64) as usize;
@ -142,7 +142,7 @@ where
S: HasRand<R>, S: HasRand<R>,
R: Rand, R: Rand,
{ {
if input.bytes().len() == 0 { if input.bytes().is_empty() {
Ok(MutationResult::Skipped) Ok(MutationResult::Skipped)
} else { } else {
let idx = state.rand_mut().below(input.bytes().len() as u64) as usize; let idx = state.rand_mut().below(input.bytes().len() as u64) as usize;
@ -160,7 +160,7 @@ where
S: HasRand<R>, S: HasRand<R>,
R: Rand, R: Rand,
{ {
if input.bytes().len() == 0 { if input.bytes().is_empty() {
Ok(MutationResult::Skipped) Ok(MutationResult::Skipped)
} else { } else {
let idx = state.rand_mut().below(input.bytes().len() as u64) as usize; let idx = state.rand_mut().below(input.bytes().len() as u64) as usize;
@ -179,7 +179,7 @@ where
S: HasRand<R>, S: HasRand<R>,
R: Rand, R: Rand,
{ {
if input.bytes().len() == 0 { if input.bytes().is_empty() {
Ok(MutationResult::Skipped) Ok(MutationResult::Skipped)
} else { } else {
let idx = state.rand_mut().below(input.bytes().len() as u64) as usize; let idx = state.rand_mut().below(input.bytes().len() as u64) as usize;
@ -198,7 +198,7 @@ where
S: HasRand<R>, S: HasRand<R>,
R: Rand, R: Rand,
{ {
if input.bytes().len() == 0 { if input.bytes().is_empty() {
Ok(MutationResult::Skipped) Ok(MutationResult::Skipped)
} else { } else {
let idx = state.rand_mut().below(input.bytes().len() as u64) as usize; let idx = state.rand_mut().below(input.bytes().len() as u64) as usize;
@ -216,7 +216,7 @@ where
S: HasRand<R>, S: HasRand<R>,
R: Rand, R: Rand,
{ {
if input.bytes().len() == 0 { if input.bytes().is_empty() {
Ok(MutationResult::Skipped) Ok(MutationResult::Skipped)
} else { } else {
let idx = state.rand_mut().below(input.bytes().len() as u64) as usize; let idx = state.rand_mut().below(input.bytes().len() as u64) as usize;
@ -234,7 +234,7 @@ where
S: HasRand<R>, S: HasRand<R>,
R: Rand, R: Rand,
{ {
if input.bytes().len() == 0 { if input.bytes().is_empty() {
Ok(MutationResult::Skipped) Ok(MutationResult::Skipped)
} else { } else {
let idx = state.rand_mut().below(input.bytes().len() as u64) as usize; let idx = state.rand_mut().below(input.bytes().len() as u64) as usize;
@ -335,7 +335,7 @@ where
S: HasRand<R>, S: HasRand<R>,
R: Rand, R: Rand,
{ {
if input.bytes().len() == 0 { if input.bytes().is_empty() {
Ok(MutationResult::Skipped) Ok(MutationResult::Skipped)
} else { } else {
let idx = state.rand_mut().below(input.bytes().len() as u64) as usize; let idx = state.rand_mut().below(input.bytes().len() as u64) as usize;

View File

@ -76,10 +76,10 @@ impl Tokens {
// we are only interested in '"..."', not prefixed 'foo = ' // we are only interested in '"..."', not prefixed 'foo = '
let start = line.chars().nth(0); let start = line.chars().nth(0);
if line.len() == 0 || start == Some('#') { if line.is_empty() || start == Some('#') {
continue; continue;
} }
let pos_quote = match line.find("\"") { let pos_quote = match line.find('\"') {
Some(x) => x, Some(x) => x,
_ => return Err(Error::IllegalArgument("Illegal line: ".to_owned() + line)), _ => return Err(Error::IllegalArgument("Illegal line: ".to_owned() + line)),
}; };
@ -92,7 +92,7 @@ impl Tokens {
Some(x) => x, Some(x) => x,
_ => return Err(Error::IllegalArgument("Illegal line: ".to_owned() + line)), _ => return Err(Error::IllegalArgument("Illegal line: ".to_owned() + line)),
}; };
if item.len() == 0 { if item.is_empty() {
continue; continue;
} }
@ -134,7 +134,7 @@ where
if meta.is_none() { if meta.is_none() {
return Ok(MutationResult::Skipped); return Ok(MutationResult::Skipped);
} }
if meta.unwrap().tokens().len() == 0 { if meta.unwrap().tokens().is_empty() {
return Ok(MutationResult::Skipped); return Ok(MutationResult::Skipped);
} }
meta.unwrap().tokens().len() meta.unwrap().tokens().len()
@ -180,7 +180,7 @@ where
if meta.is_none() { if meta.is_none() {
return Ok(MutationResult::Skipped); return Ok(MutationResult::Skipped);
} }
if meta.unwrap().tokens().len() == 0 { if meta.unwrap().tokens().is_empty() {
return Ok(MutationResult::Skipped); return Ok(MutationResult::Skipped);
} }
meta.unwrap().tokens().len() meta.unwrap().tokens().len()

View File

@ -118,7 +118,7 @@ where
{ {
/// Creates a new MapObserver /// Creates a new MapObserver
pub fn new(name: &'static str, map: &'static mut [T]) -> Self { pub fn new(name: &'static str, map: &'static mut [T]) -> Self {
let initial = if map.len() > 0 { map[0] } else { T::default() }; let initial = if map.is_empty() { T::default() } else { map[0] };
Self { Self {
map: ArrayMut::Cptr((map.as_mut_ptr(), map.len())), map: ArrayMut::Cptr((map.as_mut_ptr(), map.len())),
name: name.to_string(), name: name.to_string(),
@ -128,13 +128,15 @@ where
/// Creates a new MapObserver from a raw pointer /// Creates a new MapObserver from a raw pointer
pub fn new_from_ptr(name: &'static str, map_ptr: *mut T, len: usize) -> Self { pub fn new_from_ptr(name: &'static str, map_ptr: *mut T, len: usize) -> Self {
unsafe { let initial = if len > 0 {
let initial = if len > 0 { *map_ptr } else { T::default() }; unsafe { *map_ptr }
StdMapObserver { } else {
map: ArrayMut::Cptr((map_ptr, len)), T::default()
name: name.to_string(), };
initial, StdMapObserver {
} map: ArrayMut::Cptr((map_ptr, len)),
name: name.to_string(),
initial,
} }
} }
} }
@ -229,14 +231,16 @@ where
max_len: usize, max_len: usize,
size_ptr: *const usize, size_ptr: *const usize,
) -> Self { ) -> Self {
unsafe { let initial = if max_len > 0 {
let initial = if max_len > 0 { *map_ptr } else { T::default() }; unsafe { *map_ptr }
VariableMapObserver { } else {
map: ArrayMut::Cptr((map_ptr, max_len)), T::default()
size: Cptr::Cptr(size_ptr), };
name: name.into(), VariableMapObserver {
initial, map: ArrayMut::Cptr((map_ptr, max_len)),
} size: Cptr::Cptr(size_ptr),
name: name.into(),
initial,
} }
} }
} }

View File

@ -515,9 +515,9 @@ where
self.solutions_mut().add(Testcase::new(input.clone()))?; self.solutions_mut().add(Testcase::new(input.clone()))?;
} }
if !self if self
.add_if_interesting(&input, fitness, scheduler)? .add_if_interesting(&input, fitness, scheduler)?
.is_none() .is_some()
{ {
let observers_buf = manager.serialize_observers(observers)?; let observers_buf = manager.serialize_observers(observers)?;
manager.fire( manager.fire(
@ -564,7 +564,7 @@ where
let path = entry.path(); let path = entry.path();
let attributes = fs::metadata(&path); let attributes = fs::metadata(&path);
if !attributes.is_ok() { if attributes.is_err() {
continue; continue;
} }