Skip to content

Commit

Permalink
make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
endeav0r committed Jun 18, 2023
1 parent 52a68ac commit 9d93593
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 29 deletions.
8 changes: 4 additions & 4 deletions lib/graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ where
.vertices
.iter()
.map(|v| {
let label = v.1.dot_label().replace("\n", "\\l");
let label = v.1.dot_label().replace('\n', "\\l");
let fill_color = v.1.dot_fill_color();
let font_color = v.1.dot_font_color();
format!(
Expand All @@ -1014,7 +1014,7 @@ where
.edges
.iter()
.map(|e| {
let label = e.1.dot_label().replace("\n", "\\l");
let label = e.1.dot_label().replace('\n', "\\l");
let style = e.1.dot_style();
let fill_color = e.1.dot_fill_color();
let font_color = e.1.dot_font_color();
Expand Down Expand Up @@ -1483,7 +1483,7 @@ mod tests {
#[test]
fn test_is_acyclic_should_return_false_for_cyclic_graph() {
let graph = create_test_graph();
assert_eq!(graph.is_acyclic(1), false);
assert!(!graph.is_acyclic(1));
}

#[test]
Expand Down Expand Up @@ -1523,7 +1523,7 @@ mod tests {
graph
};

assert_eq!(graph.is_reducible(1).unwrap(), false);
assert!(!graph.is_reducible(1).unwrap());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion lib/il/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl Constant {
.value
.to_usize()
.map(|bits| {
if bits as usize >= self.bits() {
if bits >= self.bits() {
BigUint::from_u64(0).unwrap()
} else {
self.value.clone() << bits
Expand Down
2 changes: 1 addition & 1 deletion lib/il/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<'p> RefProgramLocation<'p> {
continue;
}

if function == None {
if function.is_none() {
function = Some(f);
continue;
}
Expand Down
5 changes: 1 addition & 4 deletions lib/loader/elf/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,7 @@ impl Loader for Elf {
);
}

Ok(function_entries
.into_iter()
.map(|(_, entry)| entry)
.collect())
Ok(function_entries.into_values().collect())
}

fn program_entry(&self) -> u64 {
Expand Down
14 changes: 6 additions & 8 deletions lib/loader/elf/elf_linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl ElfLinker {
}
} else {
// Ensure all shared objects we rely on are loaded
for so_name in self.loaded[&filename].dt_needed()?.clone() {
for so_name in self.loaded[&filename].dt_needed()? {
if self.loaded.get(&so_name).is_none() {
self.next_lib_address += LIB_BASE_STEP;
let next_lib_address = self.next_lib_address;
Expand Down Expand Up @@ -289,7 +289,7 @@ impl ElfLinker {
None => bail!("Could not resolve symbol {}", sym_name),
};
self.memory
.set32(reloc.r_offset as u64 + elf.base_address(), value)?;
.set32(reloc.r_offset + elf.base_address(), value)?;
}
goblin::elf::reloc::R_386_GOT32 => {
bail!("R_386_GOT32");
Expand Down Expand Up @@ -322,7 +322,7 @@ impl ElfLinker {
}
};
self.memory
.set32(reloc.r_offset as u64 + elf.base_address(), value)?;
.set32(reloc.r_offset + elf.base_address(), value)?;
}
goblin::elf::reloc::R_386_JMP_SLOT => {
let sym = &dynsyms
Expand All @@ -334,12 +334,10 @@ impl ElfLinker {
None => bail!("Could not resolve symbol {}", sym_name),
};
self.memory
.set32(reloc.r_offset as u64 + elf.base_address(), value)?;
.set32(reloc.r_offset + elf.base_address(), value)?;
}
goblin::elf::reloc::R_386_RELATIVE => {
let value = self
.memory
.get32(reloc.r_offset as u64 + elf.base_address());
let value = self.memory.get32(reloc.r_offset + elf.base_address());
let value = match value {
Some(value) => elf.base_address() as u32 + value,
None => bail!(
Expand All @@ -349,7 +347,7 @@ impl ElfLinker {
),
};
self.memory
.set32(reloc.r_offset as u64 + elf.base_address(), value)?;
.set32(reloc.r_offset + elf.base_address(), value)?;
}
goblin::elf::reloc::R_386_GOTPC => {
bail!("R_386_GOT_PC");
Expand Down
2 changes: 1 addition & 1 deletion lib/loader/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Json {
};

let bytes = match segment["bytes"] {
Value::String(ref bytes) => base64::decode(&bytes)?,
Value::String(ref bytes) => base64::decode(bytes)?,
_ => bail!("bytes missing for segment"),
};

Expand Down
2 changes: 1 addition & 1 deletion lib/memory/paged.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ where
/// Set memory permissions for the page at the given address
pub fn set_permissions(&mut self, address: u64, len: u64, permissions: MemoryPermissions) {
let mut page_address = address & PAGE_MASK;
let total_length = len as u64 + (address - page_address);
let total_length = len + (address - page_address);
while page_address < total_length {
RC::make_mut(
self.pages
Expand Down
6 changes: 3 additions & 3 deletions lib/translator/aarch64/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ pub(super) fn b_cc(

pub(super) fn br(
instruction_graph: &mut il::ControlFlowGraph,
_successors: &mut Vec<(u64, Option<il::Expression>)>,
_successors: &mut [(u64, Option<il::Expression>)],
instruction: &bad64::Instruction,
) -> Result<()> {
let block_index = {
Expand Down Expand Up @@ -799,7 +799,7 @@ fn cbz_cbnz_tbz_tbnz(
let (dst, mut cond_true, mut cond_false);

let opr_value = 0;
let opr_bit = test_bit.then(|| 1);
let opr_bit = test_bit.then_some(1);
let opr_target = [1, 2][test_bit as usize];

let block_index = {
Expand Down Expand Up @@ -1202,7 +1202,7 @@ pub(super) fn nop(

pub(super) fn ret(
instruction_graph: &mut il::ControlFlowGraph,
_successors: &mut Vec<(u64, Option<il::Expression>)>,
_successors: &mut [(u64, Option<il::Expression>)],
_instruction: &bad64::Instruction,
) -> Result<()> {
let block_index = {
Expand Down
3 changes: 1 addition & 2 deletions lib/translator/aarch64/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ fn init_driver_block<'d>(
.chain(Some(&NOP))
// The following code can be rewritten as `encoding.to_le_bytes()
// .into_iter()` in Rust 2021 but not in Rust 2018
.map(|encoding| IntoIterator::into_iter(encoding.to_le_bytes()))
.flatten()
.flat_map(|encoding| IntoIterator::into_iter(encoding.to_le_bytes()))
.collect();

let mut backing = memory::backing::Memory::new(Endian::Big);
Expand Down
2 changes: 1 addition & 1 deletion lib/translator/block_translation_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl BlockTranslationResult {
control_flow_graph.set_entry(block_index)?;
control_flow_graph.set_exit(block_index)?;

for &(_, ref cfg) in &self.instructions {
for (_, cfg) in &self.instructions {
control_flow_graph.append(cfg)?;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/translator/mips/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2070,7 +2070,7 @@ fn nop() {
_ => None,
};

assert_eq!(nop.is_some(), true);
assert!(nop.is_some());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion lib/translator/ppc/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ pub fn addze(

let src = Expression::add(
lhs.clone(),
Expression::zext(lhs.bits() as usize, expr_scalar("carry", 1))?,
Expression::zext(lhs.bits(), expr_scalar("carry", 1))?,
)?;
block.assign(dst, src);

Expand Down
2 changes: 1 addition & 1 deletion lib/translator/x86/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Mode {
Expr::add(op, expr_const(mem.disp as u64, self.bits()))?
}
Ordering::Less => {
Expr::sub(op, expr_const(mem.disp.abs() as u64, self.bits()))?
Expr::sub(op, expr_const(mem.disp.unsigned_abs(), self.bits()))?
}
Ordering::Equal => op,
}
Expand Down

0 comments on commit 9d93593

Please sign in to comment.