some clippy fixes
This commit is contained in:
parent
706d5c710d
commit
dbd3cbd99c
@ -71,7 +71,6 @@ macro_rules! create_serde_registry_for_trait {
|
||||
pub mod $mod_name {
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use alloc::string::String;
|
||||
use core::any::{Any, TypeId};
|
||||
use core::fmt;
|
||||
use postcard;
|
||||
@ -260,7 +259,7 @@ macro_rules! create_serde_registry_for_trait {
|
||||
|
||||
impl NamedSerdeAnyMap {
|
||||
#[inline]
|
||||
pub fn get<T>(&self, name: &String) -> Option<&T>
|
||||
pub fn get<T>(&self, name: &str) -> Option<&T>
|
||||
where
|
||||
T: Any,
|
||||
{
|
||||
@ -273,11 +272,7 @@ macro_rules! create_serde_registry_for_trait {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn by_typeid(
|
||||
&self,
|
||||
name: &String,
|
||||
typeid: &TypeId,
|
||||
) -> Option<&dyn $trait_name> {
|
||||
pub fn by_typeid(&self, name: &str, typeid: &TypeId) -> Option<&dyn $trait_name> {
|
||||
match self.map.get(&unpack_type_id(*typeid)) {
|
||||
None => None,
|
||||
Some(h) => h
|
||||
@ -287,7 +282,7 @@ macro_rules! create_serde_registry_for_trait {
|
||||
}
|
||||
|
||||
#[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
|
||||
T: Any,
|
||||
{
|
||||
@ -302,7 +297,7 @@ macro_rules! create_serde_registry_for_trait {
|
||||
#[inline]
|
||||
pub fn by_typeid_mut(
|
||||
&mut self,
|
||||
name: &String,
|
||||
name: &str,
|
||||
typeid: &TypeId,
|
||||
) -> Option<&mut dyn $trait_name> {
|
||||
match self.map.get_mut(&unpack_type_id(*typeid)) {
|
||||
@ -423,7 +418,7 @@ macro_rules! create_serde_registry_for_trait {
|
||||
}
|
||||
|
||||
#[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());
|
||||
if !self.map.contains_key(&id) {
|
||||
self.map.insert(id, HashMap::default());
|
||||
@ -448,7 +443,7 @@ macro_rules! create_serde_registry_for_trait {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn contains<T>(&self, name: &String) -> bool
|
||||
pub fn contains<T>(&self, name: &str) -> bool
|
||||
where
|
||||
T: Any,
|
||||
{
|
||||
|
@ -71,7 +71,7 @@ pub trait ShMem: Sized + Debug {
|
||||
fn description(&self) -> ShMemDescription {
|
||||
ShMemDescription {
|
||||
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")]
|
||||
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 std::ffi::CStr;
|
||||
|
||||
@ -222,7 +222,7 @@ pub mod shmem {
|
||||
pub fn from_str(shm_str: &CStr, map_size: usize) -> Result<Self, Error> {
|
||||
let mut ret = afl_shmem_unitialized();
|
||||
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)
|
||||
} else {
|
||||
Err(Error::Unknown(format!(
|
||||
@ -235,7 +235,7 @@ pub mod shmem {
|
||||
pub fn new(map_size: usize) -> Result<Self, Error> {
|
||||
let mut ret = afl_shmem_unitialized();
|
||||
let map = unsafe { afl_shmem_init(&mut ret, map_size) };
|
||||
if map != 0 as *mut u8 {
|
||||
if !map.is_null() {
|
||||
Ok(ret)
|
||||
} else {
|
||||
Err(Error::Unknown(format!(
|
||||
@ -253,24 +253,24 @@ pub mod shmem {
|
||||
// Not set or not initialized;
|
||||
return;
|
||||
}
|
||||
(*shm).shm_str[0 as usize] = '\u{0}' as u8;
|
||||
shmctl((*shm).shm_id, 0 as c_int, 0 as *mut shmid_ds);
|
||||
(*shm).map = 0 as *mut c_uchar;
|
||||
(*shm).shm_str[0 as usize] = 0u8;
|
||||
shmctl((*shm).shm_id, 0 as c_int, ptr::null_mut());
|
||||
(*shm).map = ptr::null_mut();
|
||||
}
|
||||
|
||||
/// Functions to create Shared memory region, for observation channels and
|
||||
/// opening inputs and stuff.
|
||||
unsafe fn afl_shmem_init(shm: *mut UnixShMem, map_size: usize) -> *mut c_uchar {
|
||||
(*shm).map_size = map_size;
|
||||
(*shm).map = 0 as *mut c_uchar;
|
||||
(*shm).map = ptr::null_mut();
|
||||
(*shm).shm_id = shmget(
|
||||
0 as c_int,
|
||||
map_size as c_ulong,
|
||||
0o1000 as c_int | 0o2000 as c_int | 0o600 as c_int,
|
||||
);
|
||||
if (*shm).shm_id < 0 as c_int {
|
||||
(*shm).shm_str[0] = '\u{0}' as u8;
|
||||
return 0 as *mut c_uchar;
|
||||
(*shm).shm_str[0] = 0u8;
|
||||
return ptr::null_mut();
|
||||
}
|
||||
snprintf(
|
||||
(*shm).shm_str.as_mut_ptr() as *mut c_char,
|
||||
@ -280,13 +280,13 @@ pub mod shmem {
|
||||
);
|
||||
(*shm).shm_str
|
||||
[(size_of::<[c_char; 20]>() as c_ulong).wrapping_sub(1 as c_int as c_ulong) as usize] =
|
||||
'\u{0}' as u8;
|
||||
(*shm).map = shmat((*shm).shm_id, 0 as *const c_void, 0 as c_int) as *mut c_uchar;
|
||||
0u8;
|
||||
(*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() {
|
||||
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_str[0 as c_int as usize] = '\u{0}' as u8;
|
||||
return 0 as *mut c_uchar;
|
||||
(*shm).shm_str[0 as c_int as usize] = 0u8;
|
||||
return ptr::null_mut();
|
||||
}
|
||||
return (*shm).map;
|
||||
}
|
||||
@ -297,10 +297,10 @@ pub mod shmem {
|
||||
shm_str: &CStr,
|
||||
map_size: usize,
|
||||
) -> *mut c_uchar {
|
||||
if shm.is_null() || shm_str.to_bytes().len() == 0 || map_size == 0 {
|
||||
return 0 as *mut c_uchar;
|
||||
if shm.is_null() || shm_str.to_bytes().is_empty() || map_size == 0 {
|
||||
return ptr::null_mut();
|
||||
}
|
||||
(*shm).map = 0 as *mut c_uchar;
|
||||
(*shm).map = ptr::null_mut();
|
||||
(*shm).map_size = map_size;
|
||||
strncpy(
|
||||
(*shm).shm_str.as_mut_ptr() as *mut c_char,
|
||||
@ -312,12 +312,12 @@ pub mod shmem {
|
||||
.expect(&format!("illegal shm_str {:?}", shm_str))
|
||||
.parse::<i32>()
|
||||
.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 {
|
||||
(*shm).map = 0 as *mut c_uchar;
|
||||
(*shm).map = ptr::null_mut();
|
||||
(*shm).map_size = 0;
|
||||
(*shm).shm_str[0] = '\u{0}' as u8;
|
||||
return 0 as *mut c_uchar;
|
||||
(*shm).shm_str[0] = 0u8;
|
||||
return ptr::null_mut();
|
||||
}
|
||||
return (*shm).map;
|
||||
}
|
||||
|
@ -6,6 +6,9 @@ use core::any::TypeId;
|
||||
|
||||
pub trait HasLen {
|
||||
fn len(&self) -> usize;
|
||||
fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
}
|
||||
|
||||
impl HasLen for () {
|
||||
|
@ -37,6 +37,12 @@ impl TopRatedsMetadata {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for TopRatedsMetadata {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub trait FavFactor<I>
|
||||
where
|
||||
I: Input,
|
||||
|
@ -128,6 +128,7 @@ where
|
||||
I: Input,
|
||||
R: Rand,
|
||||
{
|
||||
/// Create a new RandCorpusScheduler that just schedules randomly.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
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>;
|
||||
|
@ -35,18 +35,15 @@ where
|
||||
/// Add an entry to the corpus and return its index
|
||||
#[inline]
|
||||
fn add(&mut self, mut testcase: Testcase<I>) -> Result<usize, Error> {
|
||||
match testcase.filename() {
|
||||
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");
|
||||
testcase.set_filename(filename_str.into());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if let None = testcase.filename() {
|
||||
// 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");
|
||||
testcase.set_filename(filename_str.into());
|
||||
};
|
||||
testcase
|
||||
.store_input()
|
||||
.expect("Could not save testcase to disk".into());
|
||||
.expect("Could not save testcase to disk");
|
||||
self.entries.push(RefCell::new(testcase));
|
||||
Ok(self.entries.len() - 1)
|
||||
}
|
||||
|
@ -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(feature = "std")]
|
||||
|
@ -181,7 +181,7 @@ where
|
||||
#[inline]
|
||||
pub fn with_fitness(input: I, fitness: u32) -> Self {
|
||||
Testcase {
|
||||
input: Some(input.into()),
|
||||
input: Some(input),
|
||||
filename: None,
|
||||
fitness: fitness,
|
||||
metadata: SerdeAnyMap::new(),
|
||||
|
@ -167,10 +167,7 @@ where
|
||||
|
||||
/// Returns if we are the broker
|
||||
pub fn is_broker(&self) -> bool {
|
||||
match self.llmp {
|
||||
llmp::LlmpConnection::IsBroker { broker: _ } => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.llmp, llmp::LlmpConnection::IsBroker { broker: _ })
|
||||
}
|
||||
|
||||
/// Run forever in the broker
|
||||
@ -284,9 +281,9 @@ where
|
||||
// TODO include ExitKind in NewTestcase
|
||||
let fitness = state.is_interesting(&input, &observers, ExitKind::Ok)?;
|
||||
if fitness > 0 {
|
||||
if !state
|
||||
if state
|
||||
.add_if_interesting(&input, fitness, scheduler)?
|
||||
.is_none()
|
||||
.is_some()
|
||||
{
|
||||
#[cfg(feature = "std")]
|
||||
println!("Added received Testcase");
|
||||
@ -312,12 +309,9 @@ where
|
||||
/// 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,
|
||||
fn await_restart_safe(&mut self) {
|
||||
match &self.llmp {
|
||||
llmp::LlmpConnection::IsClient { client } => {
|
||||
// wait until we can drop the message safely.
|
||||
client.await_save_to_unmap_blocking();
|
||||
}
|
||||
_ => (),
|
||||
if let llmp::LlmpConnection::IsClient { client } = &self.llmp {
|
||||
// wait until we can drop the message safely.
|
||||
client.await_save_to_unmap_blocking();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ where
|
||||
OT: ObserversTuple,
|
||||
{
|
||||
let count = self.events.len();
|
||||
while self.events.len() > 0 {
|
||||
while !self.events.is_empty() {
|
||||
let event = self.events.pop().unwrap();
|
||||
self.handle_in_client(state, event)?;
|
||||
}
|
||||
@ -118,11 +118,9 @@ where
|
||||
|
||||
// Handle arriving events in the client
|
||||
fn handle_in_client(&mut self, _state: &mut S, event: Event<I>) -> Result<(), Error> {
|
||||
match event {
|
||||
_ => Err(Error::Unknown(format!(
|
||||
"Received illegal message that message should not have arrived: {:?}.",
|
||||
event
|
||||
))),
|
||||
}
|
||||
Err(Error::Unknown(format!(
|
||||
"Received illegal message that message should not have arrived: {:?}.",
|
||||
event
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
@ -77,9 +77,7 @@ where
|
||||
{
|
||||
#[cfg(unix)]
|
||||
#[cfg(feature = "std")]
|
||||
unsafe {
|
||||
reset_oncrash_ptrs();
|
||||
}
|
||||
reset_oncrash_ptrs();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -206,7 +204,7 @@ pub mod unix_signals {
|
||||
S: HasObjectives<OFT, I> + HasSolutions<OC, I>,
|
||||
I: Input,
|
||||
{
|
||||
if CURRENT_INPUT_PTR == ptr::null() {
|
||||
if CURRENT_INPUT_PTR.is_null() {
|
||||
#[cfg(target_os = "android")]
|
||||
let si_addr = { ((info._pad[0] as usize) | ((info._pad[1] as usize) << 32)) as usize };
|
||||
#[cfg(not(target_os = "android"))]
|
||||
@ -250,19 +248,19 @@ pub mod unix_signals {
|
||||
let obj_fitness = state
|
||||
.objectives_mut()
|
||||
.is_interesting_all(&input, observers, ExitKind::Crash)
|
||||
.expect("In crash handler objectives failure.".into());
|
||||
.expect("In crash handler objectives failure.");
|
||||
if obj_fitness > 0 {
|
||||
state
|
||||
.solutions_mut()
|
||||
.add(Testcase::new(input.clone()))
|
||||
.expect("In crash handler solutions failure.".into());
|
||||
.expect("In crash handler solutions failure.");
|
||||
mgr.fire(
|
||||
state,
|
||||
Event::Objective {
|
||||
objective_size: state.solutions().count(),
|
||||
},
|
||||
)
|
||||
.expect("Could not send crashing input".into());
|
||||
.expect("Could not send crashing input");
|
||||
}
|
||||
|
||||
mgr.on_restart(state).unwrap();
|
||||
@ -305,19 +303,19 @@ pub mod unix_signals {
|
||||
let obj_fitness = state
|
||||
.objectives_mut()
|
||||
.is_interesting_all(&input, observers, ExitKind::Crash)
|
||||
.expect("In timeout handler objectives failure.".into());
|
||||
.expect("In timeout handler objectives failure.");
|
||||
if obj_fitness > 0 {
|
||||
state
|
||||
.solutions_mut()
|
||||
.add(Testcase::new(input.clone()))
|
||||
.expect("In timeout handler solutions failure.".into());
|
||||
.expect("In timeout handler solutions failure.");
|
||||
mgr.fire(
|
||||
state,
|
||||
Event::Objective {
|
||||
objective_size: state.solutions().count(),
|
||||
},
|
||||
)
|
||||
.expect("Could not send timeouting input".into());
|
||||
.expect("Could not send timeouting input");
|
||||
}
|
||||
|
||||
mgr.on_restart(state).unwrap();
|
||||
@ -331,6 +329,10 @@ pub mod unix_signals {
|
||||
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]
|
||||
pub unsafe fn set_oncrash_ptrs<EM, I, OT, S>(
|
||||
state: &mut S,
|
||||
@ -344,14 +346,20 @@ pub mod unix_signals {
|
||||
OBSERVERS_PTR = observers as *const _ as *const c_void;
|
||||
}
|
||||
|
||||
/// Resets the oncrash pointers to null
|
||||
#[inline]
|
||||
pub unsafe fn reset_oncrash_ptrs() {
|
||||
CURRENT_INPUT_PTR = ptr::null();
|
||||
STATE_PTR = ptr::null_mut();
|
||||
EVENT_MGR_PTR = ptr::null_mut();
|
||||
OBSERVERS_PTR = ptr::null();
|
||||
pub fn reset_oncrash_ptrs() {
|
||||
unsafe {
|
||||
CURRENT_INPUT_PTR = ptr::null();
|
||||
STATE_PTR = ptr::null_mut();
|
||||
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>()
|
||||
where
|
||||
EM: EventManager<I, S>,
|
||||
|
@ -59,7 +59,7 @@ where
|
||||
I: Input + HasTargetBytes,
|
||||
{
|
||||
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()))
|
||||
} else {
|
||||
Ok(ExitKind::Ok)
|
||||
|
@ -218,19 +218,13 @@ where
|
||||
}
|
||||
|
||||
fn append_metadata(&mut self, testcase: &mut Testcase<I>) -> Result<(), Error> {
|
||||
match self.indexes.as_mut() {
|
||||
Some(v) => {
|
||||
let meta = MapIndexesMetadata::new(core::mem::take(v));
|
||||
testcase.add_metadata(meta);
|
||||
}
|
||||
None => {}
|
||||
if let Some(v) = self.indexes.as_mut() {
|
||||
let meta = MapIndexesMetadata::new(core::mem::take(v));
|
||||
testcase.add_metadata(meta);
|
||||
};
|
||||
match self.novelties.as_mut() {
|
||||
Some(v) => {
|
||||
let meta = MapNoveltiesMetadata::new(core::mem::take(v));
|
||||
testcase.add_metadata(meta);
|
||||
}
|
||||
None => {}
|
||||
if let Some(v) = self.novelties.as_mut() {
|
||||
let meta = MapNoveltiesMetadata::new(core::mem::take(v));
|
||||
testcase.add_metadata(meta);
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
@ -184,3 +184,9 @@ impl CrashFeedback {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for CrashFeedback {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ where
|
||||
/// Generates up to DUMMY_BYTES_MAX non-random dummy bytes (0)
|
||||
fn generate_dummy(&self) -> BytesInput {
|
||||
let size = min(self.max_size, DUMMY_BYTES_MAX);
|
||||
BytesInput::new(vec!['0' as u8; size])
|
||||
BytesInput::new(vec![0u8; size])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,6 +97,10 @@ pub trait HasBytesVec {
|
||||
|
||||
/// Has a length field
|
||||
pub trait HasLen {
|
||||
/// The lenght
|
||||
/// The length
|
||||
fn len(&self) -> usize;
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ where
|
||||
/// Mem move in the own vec
|
||||
#[inline]
|
||||
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!(to + len <= data.len());
|
||||
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
|
||||
#[inline]
|
||||
pub fn buffer_copy(dst: &mut [u8], src: &[u8], from: usize, to: usize, len: usize) {
|
||||
debug_assert!(dst.len() > 0);
|
||||
debug_assert!(src.len() > 0);
|
||||
debug_assert!(!dst.is_empty());
|
||||
debug_assert!(!src.is_empty());
|
||||
debug_assert!(from + len <= src.len());
|
||||
debug_assert!(to + len <= dst.len());
|
||||
let dst_ptr = dst.as_mut_ptr();
|
||||
@ -124,7 +124,7 @@ where
|
||||
S: HasRand<R> + HasMaxSize,
|
||||
R: Rand,
|
||||
{
|
||||
if input.bytes().len() == 0 {
|
||||
if input.bytes().is_empty() {
|
||||
Ok(MutationResult::Skipped)
|
||||
} else {
|
||||
let bit = state.rand_mut().below((input.bytes().len() << 3) as u64) as usize;
|
||||
@ -142,7 +142,7 @@ where
|
||||
S: HasRand<R>,
|
||||
R: Rand,
|
||||
{
|
||||
if input.bytes().len() == 0 {
|
||||
if input.bytes().is_empty() {
|
||||
Ok(MutationResult::Skipped)
|
||||
} else {
|
||||
let idx = state.rand_mut().below(input.bytes().len() as u64) as usize;
|
||||
@ -160,7 +160,7 @@ where
|
||||
S: HasRand<R>,
|
||||
R: Rand,
|
||||
{
|
||||
if input.bytes().len() == 0 {
|
||||
if input.bytes().is_empty() {
|
||||
Ok(MutationResult::Skipped)
|
||||
} else {
|
||||
let idx = state.rand_mut().below(input.bytes().len() as u64) as usize;
|
||||
@ -179,7 +179,7 @@ where
|
||||
S: HasRand<R>,
|
||||
R: Rand,
|
||||
{
|
||||
if input.bytes().len() == 0 {
|
||||
if input.bytes().is_empty() {
|
||||
Ok(MutationResult::Skipped)
|
||||
} else {
|
||||
let idx = state.rand_mut().below(input.bytes().len() as u64) as usize;
|
||||
@ -198,7 +198,7 @@ where
|
||||
S: HasRand<R>,
|
||||
R: Rand,
|
||||
{
|
||||
if input.bytes().len() == 0 {
|
||||
if input.bytes().is_empty() {
|
||||
Ok(MutationResult::Skipped)
|
||||
} else {
|
||||
let idx = state.rand_mut().below(input.bytes().len() as u64) as usize;
|
||||
@ -216,7 +216,7 @@ where
|
||||
S: HasRand<R>,
|
||||
R: Rand,
|
||||
{
|
||||
if input.bytes().len() == 0 {
|
||||
if input.bytes().is_empty() {
|
||||
Ok(MutationResult::Skipped)
|
||||
} else {
|
||||
let idx = state.rand_mut().below(input.bytes().len() as u64) as usize;
|
||||
@ -234,7 +234,7 @@ where
|
||||
S: HasRand<R>,
|
||||
R: Rand,
|
||||
{
|
||||
if input.bytes().len() == 0 {
|
||||
if input.bytes().is_empty() {
|
||||
Ok(MutationResult::Skipped)
|
||||
} else {
|
||||
let idx = state.rand_mut().below(input.bytes().len() as u64) as usize;
|
||||
@ -335,7 +335,7 @@ where
|
||||
S: HasRand<R>,
|
||||
R: Rand,
|
||||
{
|
||||
if input.bytes().len() == 0 {
|
||||
if input.bytes().is_empty() {
|
||||
Ok(MutationResult::Skipped)
|
||||
} else {
|
||||
let idx = state.rand_mut().below(input.bytes().len() as u64) as usize;
|
||||
|
@ -76,10 +76,10 @@ impl Tokens {
|
||||
|
||||
// we are only interested in '"..."', not prefixed 'foo = '
|
||||
let start = line.chars().nth(0);
|
||||
if line.len() == 0 || start == Some('#') {
|
||||
if line.is_empty() || start == Some('#') {
|
||||
continue;
|
||||
}
|
||||
let pos_quote = match line.find("\"") {
|
||||
let pos_quote = match line.find('\"') {
|
||||
Some(x) => x,
|
||||
_ => return Err(Error::IllegalArgument("Illegal line: ".to_owned() + line)),
|
||||
};
|
||||
@ -92,7 +92,7 @@ impl Tokens {
|
||||
Some(x) => x,
|
||||
_ => return Err(Error::IllegalArgument("Illegal line: ".to_owned() + line)),
|
||||
};
|
||||
if item.len() == 0 {
|
||||
if item.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -134,7 +134,7 @@ where
|
||||
if meta.is_none() {
|
||||
return Ok(MutationResult::Skipped);
|
||||
}
|
||||
if meta.unwrap().tokens().len() == 0 {
|
||||
if meta.unwrap().tokens().is_empty() {
|
||||
return Ok(MutationResult::Skipped);
|
||||
}
|
||||
meta.unwrap().tokens().len()
|
||||
@ -180,7 +180,7 @@ where
|
||||
if meta.is_none() {
|
||||
return Ok(MutationResult::Skipped);
|
||||
}
|
||||
if meta.unwrap().tokens().len() == 0 {
|
||||
if meta.unwrap().tokens().is_empty() {
|
||||
return Ok(MutationResult::Skipped);
|
||||
}
|
||||
meta.unwrap().tokens().len()
|
||||
|
@ -118,7 +118,7 @@ where
|
||||
{
|
||||
/// Creates a new MapObserver
|
||||
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 {
|
||||
map: ArrayMut::Cptr((map.as_mut_ptr(), map.len())),
|
||||
name: name.to_string(),
|
||||
@ -128,13 +128,15 @@ where
|
||||
|
||||
/// Creates a new MapObserver from a raw pointer
|
||||
pub fn new_from_ptr(name: &'static str, map_ptr: *mut T, len: usize) -> Self {
|
||||
unsafe {
|
||||
let initial = if len > 0 { *map_ptr } else { T::default() };
|
||||
StdMapObserver {
|
||||
map: ArrayMut::Cptr((map_ptr, len)),
|
||||
name: name.to_string(),
|
||||
initial,
|
||||
}
|
||||
let initial = if len > 0 {
|
||||
unsafe { *map_ptr }
|
||||
} else {
|
||||
T::default()
|
||||
};
|
||||
StdMapObserver {
|
||||
map: ArrayMut::Cptr((map_ptr, len)),
|
||||
name: name.to_string(),
|
||||
initial,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -229,14 +231,16 @@ where
|
||||
max_len: usize,
|
||||
size_ptr: *const usize,
|
||||
) -> Self {
|
||||
unsafe {
|
||||
let initial = if max_len > 0 { *map_ptr } else { T::default() };
|
||||
VariableMapObserver {
|
||||
map: ArrayMut::Cptr((map_ptr, max_len)),
|
||||
size: Cptr::Cptr(size_ptr),
|
||||
name: name.into(),
|
||||
initial,
|
||||
}
|
||||
let initial = if max_len > 0 {
|
||||
unsafe { *map_ptr }
|
||||
} else {
|
||||
T::default()
|
||||
};
|
||||
VariableMapObserver {
|
||||
map: ArrayMut::Cptr((map_ptr, max_len)),
|
||||
size: Cptr::Cptr(size_ptr),
|
||||
name: name.into(),
|
||||
initial,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -515,9 +515,9 @@ where
|
||||
self.solutions_mut().add(Testcase::new(input.clone()))?;
|
||||
}
|
||||
|
||||
if !self
|
||||
if self
|
||||
.add_if_interesting(&input, fitness, scheduler)?
|
||||
.is_none()
|
||||
.is_some()
|
||||
{
|
||||
let observers_buf = manager.serialize_observers(observers)?;
|
||||
manager.fire(
|
||||
@ -564,7 +564,7 @@ where
|
||||
let path = entry.path();
|
||||
let attributes = fs::metadata(&path);
|
||||
|
||||
if !attributes.is_ok() {
|
||||
if attributes.is_err() {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user