more clippy fixes
This commit is contained in:
parent
dbd3cbd99c
commit
c7f1d83b6e
@ -120,8 +120,8 @@ unsafe fn shmem2page<SH: ShMem>(afl_shmem: &SH) -> *const LlmpPage {
|
||||
#[inline]
|
||||
unsafe fn llmp_msg_in_page(page: *const LlmpPage, msg: *const LlmpMsg) -> bool {
|
||||
/* DBG("llmp_msg_in_page %p within %p-%p\n", msg, page, page + page->size_total); */
|
||||
return (page as *const u8) < msg as *const u8
|
||||
&& (page as *const u8).offset((*page).size_total as isize) > msg as *const u8;
|
||||
(page as *const u8) < msg as *const u8
|
||||
&& (page as *const u8).add((*page).size_total) > msg as *const u8
|
||||
}
|
||||
|
||||
/// allign to LLMP_PREF_ALIGNNMENT=64 bytes
|
||||
@ -198,9 +198,9 @@ unsafe fn llmp_next_msg_ptr_checked<SH: ShMem>(
|
||||
) -> Result<*mut LlmpMsg, Error> {
|
||||
let page = map.page_mut();
|
||||
let map_size = map.shmem.map().len();
|
||||
let msg_begin_min = (page as *const u8).offset(size_of::<LlmpPage>() as isize);
|
||||
let msg_begin_min = (page as *const u8).add(size_of::<LlmpPage>());
|
||||
// We still need space for this msg (alloc_size).
|
||||
let msg_begin_max = (page as *const u8).offset((map_size - alloc_size) as isize);
|
||||
let msg_begin_max = (page as *const u8).add(map_size - alloc_size);
|
||||
let next = _llmp_next_msg_ptr(last_msg);
|
||||
let next_ptr = next as *const u8;
|
||||
if next_ptr >= msg_begin_min && next_ptr <= msg_begin_max {
|
||||
@ -217,9 +217,9 @@ unsafe fn llmp_next_msg_ptr_checked<SH: ShMem>(
|
||||
#[inline]
|
||||
unsafe fn _llmp_next_msg_ptr(last_msg: *const LlmpMsg) -> *mut LlmpMsg {
|
||||
/* DBG("_llmp_next_msg_ptr %p %lu + %lu\n", last_msg, last_msg->buf_len_padded, sizeof(llmp_message)); */
|
||||
return (last_msg as *mut u8)
|
||||
.offset(size_of::<LlmpMsg>() as isize)
|
||||
.offset((*last_msg).buf_len_padded as isize) as *mut LlmpMsg;
|
||||
(last_msg as *mut u8)
|
||||
.add(size_of::<LlmpMsg>())
|
||||
.add((*last_msg).buf_len_padded as usize) as *mut LlmpMsg
|
||||
}
|
||||
|
||||
/// Description of a shared map.
|
||||
@ -262,6 +262,7 @@ pub struct LlmpMsg {
|
||||
/// The message we receive
|
||||
impl LlmpMsg {
|
||||
/// Gets the buffer from this message as slice, with the corrent length.
|
||||
/// # Safety
|
||||
/// This is unsafe if somebody has access to shared mem pages on the system.
|
||||
pub unsafe fn as_slice_unsafe(&self) -> &[u8] {
|
||||
slice::from_raw_parts(self.buf.as_ptr(), self.buf_len as usize)
|
||||
@ -285,14 +286,13 @@ impl LlmpMsg {
|
||||
unsafe {
|
||||
let map_size = map.shmem.map().len();
|
||||
let buf_ptr = self.buf.as_ptr();
|
||||
if buf_ptr > (map.page_mut() as *const u8).offset(size_of::<LlmpPage>() as isize)
|
||||
if buf_ptr > (map.page_mut() as *const u8).add(size_of::<LlmpPage>())
|
||||
&& buf_ptr
|
||||
<= (map.page_mut() as *const u8)
|
||||
.offset((map_size - size_of::<LlmpMsg>() as usize) as isize)
|
||||
<= (map.page_mut() as *const u8).add(map_size - size_of::<LlmpMsg>() as usize)
|
||||
{
|
||||
// The message header is in the page. Continue with checking the body.
|
||||
let len = self.buf_len_padded as usize + size_of::<LlmpMsg>();
|
||||
buf_ptr <= (map.page_mut() as *const u8).offset((map_size - len) as isize)
|
||||
buf_ptr <= (map.page_mut() as *const u8).add(map_size - len)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
@ -448,6 +448,8 @@ where
|
||||
/// Completely reset the current sender map.
|
||||
/// Afterwards, no receiver should read from it at a different location.
|
||||
/// This is only useful if all connected llmp parties start over, for example after a crash.
|
||||
/// # Safety
|
||||
/// Only safe if you really really restart the page on everything connected
|
||||
pub unsafe fn reset(&mut self) {
|
||||
_llmp_page_init(&mut self.out_maps.last_mut().unwrap().shmem, self.id, true);
|
||||
self.last_msg_sent = ptr::null_mut();
|
||||
@ -640,7 +642,7 @@ where
|
||||
panic!("Allocated new message without calling send() inbetween. ret: {:?}, page: {:?}, complete_msg_size: {:?}, size_used: {:?}, last_msg: {:?}", ret, page,
|
||||
buf_len_padded, (*page).size_used, last_msg);
|
||||
}
|
||||
(*page).size_used = (*page).size_used + complete_msg_size;
|
||||
(*page).size_used += complete_msg_size;
|
||||
(*ret).buf_len_padded = buf_len_padded as u64;
|
||||
(*ret).buf_len = buf_len as u64;
|
||||
/* DBG("Returning new message at %p with len %ld, TAG was %x", ret, ret->buf_len_padded, ret->tag); */
|
||||
@ -714,16 +716,17 @@ where
|
||||
}
|
||||
|
||||
/// Allocates the next space on this sender page
|
||||
pub unsafe fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, Error> {
|
||||
match self.alloc_next_if_space(buf_len) {
|
||||
Some(msg) => return Ok(msg),
|
||||
_ => (),
|
||||
pub fn alloc_next(&mut self, buf_len: usize) -> Result<*mut LlmpMsg, Error> {
|
||||
if let Some(msg) = unsafe { self.alloc_next_if_space(buf_len) } {
|
||||
return Ok(msg);
|
||||
};
|
||||
|
||||
/* no more space left! We'll have to start a new page */
|
||||
unsafe {
|
||||
self.handle_out_eop()?;
|
||||
}
|
||||
|
||||
match self.alloc_next_if_space(buf_len) {
|
||||
match unsafe { self.alloc_next_if_space(buf_len) } {
|
||||
Some(msg) => Ok(msg),
|
||||
None => Err(Error::Unknown(format!(
|
||||
"Error allocating {} bytes in shmap",
|
||||
@ -733,6 +736,8 @@ where
|
||||
}
|
||||
|
||||
/// Cancel send of the next message, this allows us to allocate a new message without sending this one.
|
||||
/// # Safety
|
||||
/// They msg pointer may no longer be used after `cancel_send`
|
||||
pub unsafe fn cancel_send(&mut self, msg: *mut LlmpMsg) {
|
||||
/* DBG("Client %d cancels send of msg at %p with tag 0x%X and size %ld", client->id, msg, msg->tag,
|
||||
* msg->buf_len_padded); */
|
||||
@ -1047,11 +1052,15 @@ where
|
||||
}
|
||||
|
||||
/// Get the unsafe ptr to this page, situated on the shared map
|
||||
/// # Safety
|
||||
/// The unsafe page pointer is obviously unsafe.
|
||||
pub unsafe fn page_mut(&mut self) -> *mut LlmpPage {
|
||||
shmem2page_mut(&mut self.shmem)
|
||||
}
|
||||
|
||||
/// Get the unsafe ptr to this page, situated on the shared map
|
||||
/// # Safety
|
||||
/// The unsafe page pointer is obviously unsafe.
|
||||
pub unsafe fn page(&self) -> *const LlmpPage {
|
||||
shmem2page(&self.shmem)
|
||||
}
|
||||
@ -1250,7 +1259,7 @@ where
|
||||
let listener = TcpListener::bind(format!("127.0.0.1:{}", port))?;
|
||||
// accept connections and process them, spawning a new thread for each one
|
||||
println!("Server listening on port {}", port);
|
||||
return self.launch_tcp_listener(listener);
|
||||
self.launch_tcp_listener(listener)
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
|
@ -105,7 +105,7 @@ macro_rules! create_serde_registry_for_trait {
|
||||
.get(&id)
|
||||
.expect("Cannot deserialize an unregistered type")
|
||||
};
|
||||
let seed = DeserializeCallbackSeed::<dyn $trait_name> { cb: cb };
|
||||
let seed = DeserializeCallbackSeed::<dyn $trait_name> { cb };
|
||||
let obj: Self::Value = visitor.next_element_seed(seed)?.unwrap();
|
||||
Ok(obj)
|
||||
}
|
||||
|
@ -3,11 +3,11 @@
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(unix)]
|
||||
pub use shmem::UnixShMem;
|
||||
pub use unix_shmem::UnixShMem;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[cfg(windows)]
|
||||
pub use shmem::Win32ShMem;
|
||||
pub use unix_shmem::Win32ShMem;
|
||||
|
||||
use alloc::string::{String, ToString};
|
||||
use core::fmt::Debug;
|
||||
@ -101,7 +101,7 @@ pub trait ShMem: Sized + Debug {
|
||||
|
||||
#[cfg(unix)]
|
||||
#[cfg(feature = "std")]
|
||||
pub mod shmem {
|
||||
pub mod unix_shmem {
|
||||
|
||||
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};
|
||||
@ -288,7 +288,7 @@ pub mod shmem {
|
||||
(*shm).shm_str[0 as c_int as usize] = 0u8;
|
||||
return ptr::null_mut();
|
||||
}
|
||||
return (*shm).map;
|
||||
(*shm).map
|
||||
}
|
||||
|
||||
/// Uses a shmap id string to open a shared map
|
||||
@ -319,7 +319,7 @@ pub mod shmem {
|
||||
(*shm).shm_str[0] = 0u8;
|
||||
return ptr::null_mut();
|
||||
}
|
||||
return (*shm).map;
|
||||
(*shm).map
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,12 +68,8 @@ pub trait MatchType {
|
||||
}
|
||||
|
||||
impl MatchType for () {
|
||||
fn match_type<T: 'static>(&self, _f: fn(t: &T)) {
|
||||
()
|
||||
}
|
||||
fn match_type_mut<T: 'static>(&mut self, _f: fn(t: &mut T)) {
|
||||
()
|
||||
}
|
||||
fn match_type<T: 'static>(&self, _f: fn(t: &T)) {}
|
||||
fn match_type_mut<T: 'static>(&mut self, _f: fn(t: &mut T)) {}
|
||||
}
|
||||
|
||||
impl<Head, Tail> MatchType for (Head, Tail)
|
||||
@ -182,7 +178,7 @@ where
|
||||
|
||||
fn append(self, value: T) -> Self::AppendResult {
|
||||
let (head, tail) = self;
|
||||
return (head, tail.append(value));
|
||||
(head, tail.append(value))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,7 +214,7 @@ where
|
||||
|
||||
pub fn new(base: CS) -> Self {
|
||||
Self {
|
||||
base: base,
|
||||
base,
|
||||
skip_not_fav_prob: DEFAULT_SKIP_NOT_FAV_PROB,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
@ -222,8 +222,8 @@ where
|
||||
|
||||
pub fn with_skip_prob(base: CS, skip_not_fav_prob: u64) -> Self {
|
||||
Self {
|
||||
base: base,
|
||||
skip_not_fav_prob: skip_not_fav_prob,
|
||||
base,
|
||||
skip_not_fav_prob,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ where
|
||||
Ok(Self {
|
||||
entries: vec![],
|
||||
current: None,
|
||||
dir_path: dir_path,
|
||||
dir_path,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ where
|
||||
Testcase {
|
||||
input: Some(input),
|
||||
filename: None,
|
||||
fitness: fitness,
|
||||
fitness,
|
||||
metadata: SerdeAnyMap::new(),
|
||||
exec_time: None,
|
||||
cached_len: None,
|
||||
|
@ -280,15 +280,14 @@ where
|
||||
let observers: OT = postcard::from_bytes(&observers_buf)?;
|
||||
// TODO include ExitKind in NewTestcase
|
||||
let fitness = state.is_interesting(&input, &observers, ExitKind::Ok)?;
|
||||
if fitness > 0 {
|
||||
if state
|
||||
if fitness > 0
|
||||
&& state
|
||||
.add_if_interesting(&input, fitness, scheduler)?
|
||||
.is_some()
|
||||
{
|
||||
#[cfg(feature = "std")]
|
||||
println!("Added received Testcase");
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(Error::Unknown(format!(
|
||||
|
@ -66,7 +66,7 @@ where
|
||||
{
|
||||
pub fn new(stats: ST) -> Self {
|
||||
Self {
|
||||
stats: stats,
|
||||
stats,
|
||||
events: vec![],
|
||||
phantom: PhantomData,
|
||||
}
|
||||
|
@ -323,7 +323,7 @@ where
|
||||
/// The map can be shared.
|
||||
pub fn with_history_map(name: &'static str, history_map: Vec<T>) -> Self {
|
||||
Self {
|
||||
history_map: history_map,
|
||||
history_map,
|
||||
name: name.to_string(),
|
||||
indexes: None,
|
||||
novelties: None,
|
||||
|
@ -142,8 +142,8 @@ where
|
||||
{
|
||||
pub fn new(scheduler: CS, stages: ST) -> Self {
|
||||
Self {
|
||||
scheduler: scheduler,
|
||||
stages: stages,
|
||||
scheduler,
|
||||
stages,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ where
|
||||
{
|
||||
pub fn new(max_size: usize) -> Self {
|
||||
Self {
|
||||
max_size: max_size,
|
||||
max_size,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
@ -103,7 +103,7 @@ where
|
||||
{
|
||||
pub fn new(max_size: usize) -> Self {
|
||||
Self {
|
||||
max_size: max_size,
|
||||
max_size,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ impl From<&[u8]> for BytesInput {
|
||||
impl BytesInput {
|
||||
/// Creates a new bytes input using the given bytes
|
||||
pub fn new(bytes: Vec<u8>) -> Self {
|
||||
Self { bytes: bytes }
|
||||
Self { bytes }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -767,7 +767,7 @@ fn from_hex(hex: u8) -> Result<u8, Error> {
|
||||
if hex >= 97 && hex <= 102 {
|
||||
return Ok(hex - 87);
|
||||
}
|
||||
return Err(Error::IllegalArgument("".to_owned()));
|
||||
Err(Error::IllegalArgument("".to_owned()))
|
||||
}
|
||||
|
||||
/// Decodes a dictionary token: 'foo\x41\\and\"bar' -> 'fooA\and"bar'
|
||||
@ -801,7 +801,7 @@ pub fn str_decode(item: &str) -> Result<Vec<u8>, Error> {
|
||||
}
|
||||
}
|
||||
|
||||
return Ok(token);
|
||||
Ok(token)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -133,7 +133,7 @@ where
|
||||
/// Create a new StdScheduledMutator instance specifying mutations
|
||||
pub fn with_mutations(mutations: Vec<MutationFunction<I, S>>) -> Self {
|
||||
StdScheduledMutator {
|
||||
mutations: mutations,
|
||||
mutations,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
@ -202,7 +202,7 @@ where
|
||||
scheduled.add_mutation(mutation_bitflip);
|
||||
scheduled.add_mutation(mutation_splice);
|
||||
Self {
|
||||
scheduled: scheduled,
|
||||
scheduled,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
@ -253,7 +253,7 @@ where
|
||||
//scheduled.add_mutation(mutation_splice);
|
||||
|
||||
HavocBytesMutator {
|
||||
scheduled: scheduled,
|
||||
scheduled,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ impl Tokens {
|
||||
return false;
|
||||
}
|
||||
self.token_vec.push(token.to_vec());
|
||||
return true;
|
||||
true
|
||||
}
|
||||
|
||||
/// Reads a tokens file, returning the count of new entries read
|
||||
@ -117,7 +117,7 @@ impl Tokens {
|
||||
|
||||
/// Gets the tokens stored in this db
|
||||
pub fn tokens(&self) -> &[Vec<u8>] {
|
||||
return &self.token_vec;
|
||||
&self.token_vec
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -339,6 +339,6 @@ where
|
||||
{
|
||||
/// Creates a new MapObserver
|
||||
pub fn new(base: M) -> Self {
|
||||
Self { base: base }
|
||||
Self { base }
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ where
|
||||
/// Creates a new default mutational stage
|
||||
pub fn new(mutator: M) -> Self {
|
||||
Self {
|
||||
mutator: mutator,
|
||||
mutator,
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
@ -523,7 +523,7 @@ where
|
||||
manager.fire(
|
||||
self,
|
||||
Event::NewTestcase {
|
||||
input: input,
|
||||
input,
|
||||
observers_buf,
|
||||
corpus_size: self.corpus().count() + 1,
|
||||
client_config: "TODO".into(),
|
||||
|
@ -187,7 +187,7 @@ where
|
||||
{
|
||||
pub fn new(print_fn: F) -> Self {
|
||||
Self {
|
||||
print_fn: print_fn,
|
||||
print_fn,
|
||||
start_time: current_time(),
|
||||
corpus_size: 0,
|
||||
client_stats: vec![],
|
||||
@ -196,8 +196,8 @@ where
|
||||
|
||||
pub fn with_time(print_fn: F, start_time: time::Duration) -> Self {
|
||||
Self {
|
||||
print_fn: print_fn,
|
||||
start_time: start_time,
|
||||
print_fn,
|
||||
start_time,
|
||||
corpus_size: 0,
|
||||
client_stats: vec![],
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ impl Rand for Xoshiro256StarRand {
|
||||
|
||||
self.rand_seed[3] = self.rand_seed[3].rotate_left(45);
|
||||
|
||||
return ret;
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
@ -235,7 +235,7 @@ impl Rand for XorShift64Rand {
|
||||
x ^= x >> 7;
|
||||
x ^= x << 17;
|
||||
self.rand_seed = x;
|
||||
return x;
|
||||
x
|
||||
}
|
||||
}
|
||||
|
||||
@ -262,7 +262,7 @@ impl Rand for Lehmer64Rand {
|
||||
#[inline]
|
||||
fn next(&mut self) -> u64 {
|
||||
self.rand_seed *= 0xda942042e4dd58b5;
|
||||
return (self.rand_seed >> 64) as u64;
|
||||
(self.rand_seed >> 64) as u64
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user