Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
philipc committed Apr 12, 2023
1 parent 9f52612 commit 0ce01fa
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 35 deletions.
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.42.0"
msrv = "1.52.0"
6 changes: 3 additions & 3 deletions crates/examples/src/bin/dyldcachedump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,22 @@ fn open_subcaches_if_exist(path: &str) -> Vec<fs::File> {
let mut files = Vec::new();
for i in 1.. {
let subcache_path = format!("{}.{}", path, i);
match fs::File::open(&subcache_path) {
match fs::File::open(subcache_path) {
Ok(subcache_file) => files.push(subcache_file),
Err(_) => break,
};
}
if files.is_empty() {
for i in 1.. {
let subcache_path = format!("{}.{:02}", path, i);
match fs::File::open(&subcache_path) {
match fs::File::open(subcache_path) {
Ok(subcache_file) => files.push(subcache_file),
Err(_) => break,
};
}
}
let symbols_subcache_path = format!("{}.symbols", path);
if let Ok(subcache_file) = fs::File::open(&symbols_subcache_path) {
if let Ok(subcache_file) = fs::File::open(symbols_subcache_path) {
files.push(subcache_file);
};
println!("Found {} subcache files", files.len());
Expand Down
8 changes: 4 additions & 4 deletions crates/examples/src/bin/elfcopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ impl RedefineSymTable {
fn get_redefined_name<'a>(&'a self, original: &'a [u8]) -> &'a [u8] {
// check if we have a rename for this symbol
if let Some(map) = self.map.as_ref() {
if let Some(new_string) = map.get(original.into()) {
if let Some(new_string) = map.get(original) {
return new_string.as_slice();
}
}

return original;
original
}
}

Expand Down Expand Up @@ -921,10 +921,10 @@ fn copy_file<Elf: FileHeader<Endian = Endianness>>(
| elf::SHT_INIT_ARRAY
| elf::SHT_FINI_ARRAY => {
let out_section = &out_sections[i];
let sh_link = out_sections_index[in_section.sh_link(endian) as usize].0 as u32;
let sh_link = out_sections_index[in_section.sh_link(endian) as usize].0;
let mut sh_info = in_section.sh_info(endian);
if in_section.sh_flags(endian).into() as u32 & elf::SHF_INFO_LINK != 0 {
sh_info = out_sections_index[sh_info as usize].0 as u32;
sh_info = out_sections_index[sh_info as usize].0;
}
writer.write_section_header(&object::write::elf::SectionHeader {
name: out_section.name,
Expand Down
4 changes: 2 additions & 2 deletions crates/examples/src/bin/objdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn main() {
objdump::print(
&mut stdout.lock(),
&mut stderr.lock(),
&*file,
&file,
&extra_file_data,
member_names,
)
Expand All @@ -68,7 +68,7 @@ fn open_subcaches_if_exist(path: &str) -> Vec<fs::File> {
};
}
let symbols_subcache_path = format!("{}.symbols", path);
if let Ok(subcache_file) = fs::File::open(&symbols_subcache_path) {
if let Ok(subcache_file) = fs::File::open(symbols_subcache_path) {
files.push(subcache_file);
};
files
Expand Down
2 changes: 1 addition & 1 deletion crates/examples/src/bin/readobj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ fn main() {

let stdout = io::stdout();
let stderr = io::stderr();
readobj::print(&mut stdout.lock(), &mut stderr.lock(), &*file);
readobj::print(&mut stdout.lock(), &mut stderr.lock(), &file);
}
}
4 changes: 2 additions & 2 deletions crates/examples/src/readobj/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,10 @@ fn print_section_rela<Elf: FileHeader>(
}
}

fn print_rel_symbol<'data, Elf: FileHeader>(
fn print_rel_symbol<Elf: FileHeader>(
p: &mut Printer<'_>,
endian: Elf::Endian,
symbols: Option<SymbolTable<'data, Elf>>,
symbols: Option<SymbolTable<'_, Elf>>,
sym: u32,
) {
let name = symbols.and_then(|symbols| {
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@
#![allow(clippy::should_implement_trait)]
// Unit errors are converted to other types by callers.
#![allow(clippy::result_unit_err)]
// Clippy is wrong.
#![allow(clippy::transmute_ptr_to_ptr)]
// Worse readability sometimes.
#![allow(clippy::collapsible_else_if)]

Expand Down
2 changes: 1 addition & 1 deletion src/read/pe/data_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl pe::ImageDataDirectory {
/// not desirable for all data directories.
/// - It uses the `virtual_address` of the directory entry as an address,
/// which is not valid for `IMAGE_DIRECTORY_ENTRY_SECURITY`.
pub fn file_range<'data>(&self, sections: &SectionTable<'data>) -> Result<(u32, u32)> {
pub fn file_range(&self, sections: &SectionTable<'_>) -> Result<(u32, u32)> {
let (offset, section_size) = sections
.pe_file_range_at(self.virtual_address.get(LE))
.read_error("Invalid data dir virtual address")?;
Expand Down
5 changes: 1 addition & 4 deletions src/read/read_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ impl<'a, R: Read + Seek> ReadRef<'a> for &'a ReadCache<R> {
Entry::Occupied(entry) => entry.into_mut(),
Entry::Vacant(entry) => {
let size = size.try_into().map_err(|_| ())?;
cache
.read
.seek(SeekFrom::Start(offset as u64))
.map_err(|_| ())?;
cache.read.seek(SeekFrom::Start(offset)).map_err(|_| ())?;
let mut bytes = vec![0; size].into_boxed_slice();
cache.read.read_exact(&mut bytes).map_err(|_| ())?;
entry.insert(bytes)
Expand Down
4 changes: 2 additions & 2 deletions src/read/xcoff/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ impl<'data, 'file, Xcoff: FileHeader, R: ReadRef<'data>> ObjectSymbol<'data>
}
}
match self.symbol.n_sclass() {
xcoff::C_NULL => return SymbolKind::Null,
xcoff::C_FILE => return SymbolKind::File,
xcoff::C_NULL => SymbolKind::Null,
xcoff::C_FILE => SymbolKind::File,
_ => SymbolKind::Unknown,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/write/coff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ impl<'a> Object<'a> {
let mut coff_symbol = coff::ImageSymbol {
name: [0; 8],
value: U32Bytes::new(LE, value),
section_number: U16Bytes::new(LE, section_number as u16),
section_number: U16Bytes::new(LE, section_number),
typ: U16Bytes::new(LE, typ),
storage_class,
number_of_aux_symbols,
Expand Down
2 changes: 1 addition & 1 deletion src/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ impl<'a> Section<'a> {
self.size = offset;
}
self.size += size;
offset as u64
offset
}

/// Returns the section as-built so far.
Expand Down
22 changes: 11 additions & 11 deletions src/write/xcoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ impl<'a> Object<'a> {
if is_64 {
let section_header = xcoff::SectionHeader64 {
s_name: sectname,
s_paddr: U64::new(BE, section_offsets[index].address as u64),
s_paddr: U64::new(BE, section_offsets[index].address),
// This field has the same value as the s_paddr field.
s_vaddr: U64::new(BE, section_offsets[index].address as u64),
s_vaddr: U64::new(BE, section_offsets[index].address),
s_size: U64::new(BE, section.data.len() as u64),
s_scnptr: U64::new(BE, section_offsets[index].data_offset as u64),
s_relptr: U64::new(BE, section_offsets[index].reloc_offset as u64),
Expand Down Expand Up @@ -342,7 +342,7 @@ impl<'a> Object<'a> {
};
if is_64 {
let xcoff_rel = xcoff::Rel64 {
r_vaddr: U64::new(BE, reloc.offset as u64),
r_vaddr: U64::new(BE, reloc.offset),
r_symndx: U32::new(BE, symbol_offsets[reloc.symbol.0].index as u32),
// Specifies the bit length of the relocatable reference minus one.
r_rsize: (reloc.size - 1),
Expand Down Expand Up @@ -404,8 +404,8 @@ impl<'a> Object<'a> {
n_offset: U32::new(BE, strtab.get_offset(str_id) as u32),
n_scnum: I16::new(BE, n_scnum),
n_type: U16::new(BE, n_type),
n_sclass: n_sclass,
n_numaux: n_numaux,
n_sclass,
n_numaux,
};
buffer.write(&xcoff_sym);
} else {
Expand All @@ -423,8 +423,8 @@ impl<'a> Object<'a> {
n_value: U32::new(BE, n_value as u32),
n_scnum: I16::new(BE, n_scnum),
n_type: U16::new(BE, n_type),
n_sclass: n_sclass,
n_numaux: n_numaux,
n_sclass,
n_numaux,
};
buffer.write(&xcoff_sym);
}
Expand Down Expand Up @@ -509,8 +509,8 @@ impl<'a> Object<'a> {
x_scnlen_hi: U32::new(BE, ((scnlen >> 32) & 0xFFFFFFFF) as u32),
x_parmhash: U32::new(BE, 0),
x_snhash: U16::new(BE, 0),
x_smtyp: x_smtyp,
x_smclas: x_smclas,
x_smtyp,
x_smclas,
pad: 0,
x_auxtype: xcoff::AUX_CSECT,
};
Expand All @@ -520,8 +520,8 @@ impl<'a> Object<'a> {
x_scnlen: U32::new(BE, scnlen as u32),
x_parmhash: U32::new(BE, 0),
x_snhash: U16::new(BE, 0),
x_smtyp: x_smtyp,
x_smclas: x_smclas,
x_smtyp,
x_smclas,
x_stab: U32::new(BE, 0),
x_snstab: U16::new(BE, 0),
};
Expand Down

0 comments on commit 0ce01fa

Please sign in to comment.