Skip to content

Commit deb7655

Browse files
authored
New year new clippy (AFLplusplus#2797)
* New year new clippy * More clipy * fix
1 parent 92db678 commit deb7655

File tree

7 files changed

+30
-29
lines changed

7 files changed

+30
-29
lines changed

libafl/src/corpus/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub trait Corpus: Sized {
175175
fn nth(&self, nth: usize) -> CorpusId {
176176
self.ids()
177177
.nth(nth)
178-
.expect("Failed to get the {nth} CorpusId")
178+
.unwrap_or_else(|| panic!("Failed to get the {nth} CorpusId"))
179179
}
180180

181181
/// Get the nth corpus id; considers both enabled and disabled testcases

libafl/src/events/llmp/mgr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ where
417417
+ EvaluatorObservers<E, Self, <S::Corpus as Corpus>::Input, S>
418418
+ Evaluator<E, Self, <S::Corpus as Corpus>::Input, S>,
419419
{
420-
println!("Got event in client: {} from {:?}", event.name(), client_id);
420+
log::trace!("Got event in client: {} from {client_id:?}", event.name());
421421
if !self.hooks.pre_exec_all(state, client_id, &event)? {
422422
return Ok(());
423423
}
@@ -565,7 +565,7 @@ where
565565
#[cfg(not(feature = "llmp_compression"))]
566566
{
567567
self.llmp
568-
.send_buf(LLMP_TAG_EVENT_TO_BOTH, &self.event_buffer[..written_len]);
568+
.send_buf(LLMP_TAG_EVENT_TO_BOTH, &self.event_buffer[..written_len])?;
569569
}
570570

571571
self.last_sent = current_time();

libafl/src/mutators/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl<I, S> MutatorsTuple<I, S> for Vec<Box<dyn Mutator<I, S>>> {
353353
) -> Result<MutationResult, Error> {
354354
let mutator = self
355355
.get_mut(index.0)
356-
.ok_or_else(|| Error::key_not_found("Mutator with id {index:?} not found."))?;
356+
.ok_or_else(|| Error::key_not_found(format!("Mutator with id {index:?} not found.")))?;
357357
mutator.mutate(state, input)
358358
}
359359

@@ -365,7 +365,7 @@ impl<I, S> MutatorsTuple<I, S> for Vec<Box<dyn Mutator<I, S>>> {
365365
) -> Result<(), Error> {
366366
let mutator = self
367367
.get_mut(index)
368-
.ok_or_else(|| Error::key_not_found("Mutator with id {index:?} not found."))?;
368+
.ok_or_else(|| Error::key_not_found(format!("Mutator with id {index:?} not found.")))?;
369369
mutator.post_exec(state, new_corpus_id)
370370
}
371371
}

libafl/src/mutators/token_mutations.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ impl AFLppRedQueen {
10591059
if buf_16 == pattern as u16 && another_buf_16 == another_pattern as u16 {
10601060
let mut cloned = buf.to_vec();
10611061
cloned[buf_idx + 1] = (repl & 0xff) as u8;
1062-
cloned[buf_idx] = (repl >> 8 & 0xff) as u8;
1062+
cloned[buf_idx] = ((repl >> 8) & 0xff) as u8;
10631063
vec.push(cloned);
10641064
return Ok(true);
10651065
}
@@ -1074,9 +1074,9 @@ impl AFLppRedQueen {
10741074
if buf_32 == pattern as u32 && another_buf_32 == another_pattern as u32 {
10751075
let mut cloned = buf.to_vec();
10761076
cloned[buf_idx + 3] = (repl & 0xff) as u8;
1077-
cloned[buf_idx + 2] = (repl >> 8 & 0xff) as u8;
1078-
cloned[buf_idx + 1] = (repl >> 16 & 0xff) as u8;
1079-
cloned[buf_idx] = (repl >> 24 & 0xff) as u8;
1077+
cloned[buf_idx + 2] = ((repl >> 8) & 0xff) as u8;
1078+
cloned[buf_idx + 1] = ((repl >> 16) & 0xff) as u8;
1079+
cloned[buf_idx] = ((repl >> 24) & 0xff) as u8;
10801080
vec.push(cloned);
10811081

10821082
return Ok(true);
@@ -1093,13 +1093,13 @@ impl AFLppRedQueen {
10931093
let mut cloned = buf.to_vec();
10941094

10951095
cloned[buf_idx + 7] = (repl & 0xff) as u8;
1096-
cloned[buf_idx + 6] = (repl >> 8 & 0xff) as u8;
1097-
cloned[buf_idx + 5] = (repl >> 16 & 0xff) as u8;
1098-
cloned[buf_idx + 4] = (repl >> 24 & 0xff) as u8;
1099-
cloned[buf_idx + 3] = (repl >> 32 & 0xff) as u8;
1100-
cloned[buf_idx + 2] = (repl >> 32 & 0xff) as u8;
1101-
cloned[buf_idx + 1] = (repl >> 40 & 0xff) as u8;
1102-
cloned[buf_idx] = (repl >> 48 & 0xff) as u8;
1096+
cloned[buf_idx + 6] = ((repl >> 8) & 0xff) as u8;
1097+
cloned[buf_idx + 5] = ((repl >> 16) & 0xff) as u8;
1098+
cloned[buf_idx + 4] = ((repl >> 24) & 0xff) as u8;
1099+
cloned[buf_idx + 3] = ((repl >> 32) & 0xff) as u8;
1100+
cloned[buf_idx + 2] = ((repl >> 32) & 0xff) as u8;
1101+
cloned[buf_idx + 1] = ((repl >> 40) & 0xff) as u8;
1102+
cloned[buf_idx] = ((repl >> 48) & 0xff) as u8;
11031103

11041104
vec.push(cloned);
11051105
return Ok(true);

libafl_frida/src/helper.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,10 @@ impl FridaInstrumentationHelperBuilder {
239239
let name = path
240240
.file_name()
241241
.and_then(|name| name.to_str())
242-
.expect("Failed to get script file name from path: {path:}");
242+
.unwrap_or_else(|| panic!("Failed to get script file name from path: {path:?}"));
243243
let script_prefix = include_str!("script.js");
244-
let file_contents = read_to_string(path).expect("Failed to read script: {path:}");
244+
let file_contents = read_to_string(path)
245+
.unwrap_or_else(|err| panic!("Failed to read script {path:?}: {err:?}"));
245246
let payload = script_prefix.to_string() + &file_contents;
246247
let gum = Gum::obtain();
247248
let backend = match backend {

libafl_qemu/src/emu/hooks.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ where
182182
.push(Box::pin((InstructionHookId::invalid(), fat)));
183183

184184
unsafe {
185-
let hook_state = &mut self
185+
let hook_state = &raw mut self
186186
.instruction_hooks
187187
.last_mut()
188188
.unwrap()
189189
.as_mut()
190190
.get_unchecked_mut()
191-
.1 as *mut FatPtr;
191+
.1;
192192

193193
let id = self.qemu_hooks.add_instruction_hooks(
194194
&mut *hook_state,
@@ -656,13 +656,13 @@ where
656656
self.backdoor_hooks
657657
.push(Box::pin((BackdoorHookId::invalid(), fat)));
658658

659-
let hook_state = &mut self
659+
let hook_state = &raw mut self
660660
.backdoor_hooks
661661
.last_mut()
662662
.unwrap()
663663
.as_mut()
664664
.get_unchecked_mut()
665-
.1 as *mut FatPtr;
665+
.1;
666666

667667
let id = self
668668
.qemu_hooks
@@ -739,13 +739,13 @@ where
739739
self.new_thread_hooks
740740
.push(Box::pin((NewThreadHookId::invalid(), fat)));
741741

742-
let hook_state = &mut self
742+
let hook_state = &raw mut self
743743
.new_thread_hooks
744744
.last_mut()
745745
.unwrap()
746746
.as_mut()
747747
.get_unchecked_mut()
748-
.1 as *mut FatPtr;
748+
.1;
749749

750750
let id = self
751751
.qemu_hooks
@@ -797,13 +797,13 @@ where
797797
self.pre_syscall_hooks
798798
.push(Box::pin((PreSyscallHookId::invalid(), fat)));
799799

800-
let hook_state = &mut self
800+
let hook_state = &raw mut self
801801
.pre_syscall_hooks
802802
.last_mut()
803803
.unwrap()
804804
.as_mut()
805805
.get_unchecked_mut()
806-
.1 as *mut FatPtr;
806+
.1;
807807

808808
let id = self
809809
.qemu_hooks
@@ -848,13 +848,13 @@ where
848848
self.post_syscall_hooks
849849
.push(Box::pin((PostSyscallHookId::invalid(), fat)));
850850

851-
let hooks_state = &mut self
851+
let hooks_state = &raw mut self
852852
.post_syscall_hooks
853853
.last_mut()
854854
.unwrap()
855855
.as_mut()
856856
.get_unchecked_mut()
857-
.1 as *mut FatPtr;
857+
.1;
858858

859859
let id = self.qemu_hooks.add_post_syscall_hook(
860860
&mut *hooks_state,

libafl_qemu/src/qemu/usermode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ pub mod pybind {
286286
a6: u64,
287287
a7: u64,
288288
) -> SyscallHookResult {
289-
unsafe { PY_SYSCALL_HOOK.as_ref() }.map_or_else(
289+
unsafe { &*(&raw const PY_SYSCALL_HOOK).as_ref() }.map_or_else(
290290
|| SyscallHookResult::new(None),
291291
|obj| {
292292
let args = (sys_num, a0, a1, a2, a3, a4, a5, a6, a7);

0 commit comments

Comments
 (0)