Run cargo clippy --fix

This commit is contained in:
Christopher Cole 2022-11-13 13:14:12 -08:00
parent 9a6a265afc
commit 0f849a1e17
No known key found for this signature in database
GPG Key ID: 0AC856975983E9DB
10 changed files with 57 additions and 65 deletions

View File

@ -1373,7 +1373,7 @@ pub const R_ARM_IRELATIVE: u32 = 160;
/// Object file compatibility attributes /// Object file compatibility attributes
pub const SHT_AARCH64_ATTRIBUTES: u32 = 0x70000003; pub const SHT_AARCH64_ATTRIBUTES: u32 = 0x70000003;
pub const SHT_AARCH64_ATTRIBUTES_SECTION_NAME: &'static str = ".ARM.attributes"; pub const SHT_AARCH64_ATTRIBUTES_SECTION_NAME: &str = ".ARM.attributes";
/// Architecture compatibility information. /// Architecture compatibility information.
/// ///
@ -2147,7 +2147,7 @@ pub const EF_RISCV_RVE: u32 = 0x0008;
pub const EF_RISCV_TSO: u32 = 0x0010; pub const EF_RISCV_TSO: u32 = 0x0010;
pub const SHT_RISCV_ATTRIBUTES: u32 = 0x70000003; // SHT_LOPROC + 3; pub const SHT_RISCV_ATTRIBUTES: u32 = 0x70000003; // SHT_LOPROC + 3;
pub const SHT_RISCV_ATTRIBUTES_SECTION_NAME: &'static str = ".riscv.attributes"; pub const SHT_RISCV_ATTRIBUTES_SECTION_NAME: &str = ".riscv.attributes";
pub const PT_RISCV_ATTRIBUTES: u32 = 0x70000003; pub const PT_RISCV_ATTRIBUTES: u32 = 0x70000003;

View File

@ -576,7 +576,7 @@ impl<'data, E: EndianParse> ElfBytes<'data, E> {
/// This is the segment's data as found in the file. /// This is the segment's data as found in the file.
pub fn segment_data(&self, phdr: &ProgramHeader) -> Result<&'data [u8], ParseError> { pub fn segment_data(&self, phdr: &ProgramHeader) -> Result<&'data [u8], ParseError> {
let (start, end) = phdr.get_file_data_range()?; let (start, end) = phdr.get_file_data_range()?;
Ok(self.data.get_bytes(start..end)?) self.data.get_bytes(start..end)
} }
/// Get the segment's file data for a given [ProgramHeader], and interpret it as an /// Get the segment's file data for a given [ProgramHeader], and interpret it as an

View File

@ -174,7 +174,7 @@ impl<E: EndianParse, S: std::io::Read + std::io::Seek> ElfStream<E, S> {
&mut self, &mut self,
) -> Result<(&Vec<SectionHeader>, Option<StringTable>), ParseError> { ) -> Result<(&Vec<SectionHeader>, Option<StringTable>), ParseError> {
// It's Ok to have no section headers // It's Ok to have no section headers
if self.shdrs.len() == 0 { if self.shdrs.is_empty() {
return Ok((&self.shdrs, None)); return Ok((&self.shdrs, None));
} }
@ -331,7 +331,7 @@ impl<E: EndianParse, S: std::io::Read + std::io::Seek> ElfStream<E, S> {
&mut self, &mut self,
symtab_type: u32, symtab_type: u32,
) -> Result<Option<(SymbolTable<E>, StringTable)>, ParseError> { ) -> Result<Option<(SymbolTable<E>, StringTable)>, ParseError> {
if self.shdrs.len() == 0 { if self.shdrs.is_empty() {
return Ok(None); return Ok(None);
} }
@ -385,7 +385,7 @@ impl<E: EndianParse, S: std::io::Read + std::io::Seek> ElfStream<E, S> {
/// Get the .dynamic section/segment contents. /// Get the .dynamic section/segment contents.
pub fn dynamic(&mut self) -> Result<Option<DynamicTable<E>>, ParseError> { pub fn dynamic(&mut self) -> Result<Option<DynamicTable<E>>, ParseError> {
// If we have section headers, then look it up there // If we have section headers, then look it up there
if self.shdrs.len() > 0 { if !self.shdrs.is_empty() {
if let Some(shdr) = self if let Some(shdr) = self
.shdrs .shdrs
.iter() .iter()
@ -400,7 +400,7 @@ impl<E: EndianParse, S: std::io::Read + std::io::Seek> ElfStream<E, S> {
))); )));
} }
// Otherwise, look up the PT_DYNAMIC segment (if any) // Otherwise, look up the PT_DYNAMIC segment (if any)
} else if self.phdrs.len() > 0 { } else if !self.phdrs.is_empty() {
if let Some(phdr) = self if let Some(phdr) = self
.phdrs .phdrs
.iter() .iter()
@ -427,7 +427,7 @@ impl<E: EndianParse, S: std::io::Read + std::io::Seek> ElfStream<E, S> {
/// Returns an empty Option if the object does not use symbol versioning. /// Returns an empty Option if the object does not use symbol versioning.
pub fn symbol_version_table(&mut self) -> Result<Option<SymbolVersionTable<E>>, ParseError> { pub fn symbol_version_table(&mut self) -> Result<Option<SymbolVersionTable<E>>, ParseError> {
// No sections means no GNU symbol versioning sections, which is ok // No sections means no GNU symbol versioning sections, which is ok
if self.shdrs.len() == 0 { if self.shdrs.is_empty() {
return Ok(None); return Ok(None);
} }

View File

@ -95,7 +95,7 @@ fn verify_ident(buf: &[u8]) -> Result<(), ParseError> {
))); )));
} }
return Ok(()); Ok(())
} }
pub fn parse_ident<E: EndianParse>(data: &[u8]) -> Result<(E, Class, u8, u8), ParseError> { pub fn parse_ident<E: EndianParse>(data: &[u8]) -> Result<(E, Class, u8, u8), ParseError> {
@ -199,7 +199,7 @@ mod parse_tests {
0, 0,
0, 0,
]; ];
verify_ident(&mut data.as_ref()).expect("Expected Ok result"); verify_ident(data.as_ref()).expect("Expected Ok result");
} }
#[test] #[test]
@ -222,7 +222,7 @@ mod parse_tests {
0, 0,
0, 0,
]; ];
let result = verify_ident(&mut data.as_ref()).expect_err("Expected an error"); let result = verify_ident(data.as_ref()).expect_err("Expected an error");
assert!( assert!(
matches!(result, ParseError::BadMagic(_)), matches!(result, ParseError::BadMagic(_)),
"Unexpected Error type found: {result}" "Unexpected Error type found: {result}"
@ -249,7 +249,7 @@ mod parse_tests {
0, 0,
0, 0,
]; ];
let result = verify_ident(&mut data.as_ref()).expect_err("Expected an error"); let result = verify_ident(data.as_ref()).expect_err("Expected an error");
assert!( assert!(
matches!(result, ParseError::BadMagic(_)), matches!(result, ParseError::BadMagic(_)),
"Unexpected Error type found: {result}" "Unexpected Error type found: {result}"
@ -276,7 +276,7 @@ mod parse_tests {
0, 0,
0, 0,
]; ];
let result = verify_ident(&mut data.as_ref()).expect_err("Expected an error"); let result = verify_ident(data.as_ref()).expect_err("Expected an error");
assert!( assert!(
matches!(result, ParseError::BadMagic(_)), matches!(result, ParseError::BadMagic(_)),
"Unexpected Error type found: {result}" "Unexpected Error type found: {result}"
@ -303,7 +303,7 @@ mod parse_tests {
0, 0,
0, 0,
]; ];
let result = verify_ident(&mut data.as_ref()).expect_err("Expected an error"); let result = verify_ident(data.as_ref()).expect_err("Expected an error");
assert!( assert!(
matches!(result, ParseError::BadMagic(_)), matches!(result, ParseError::BadMagic(_)),
"Unexpected Error type found: {result}" "Unexpected Error type found: {result}"
@ -331,7 +331,7 @@ mod parse_tests {
0, 0,
0, 0,
]; ];
let result = verify_ident(&mut data.as_ref()).expect_err("Expected an error"); let result = verify_ident(data.as_ref()).expect_err("Expected an error");
assert!( assert!(
matches!(result, ParseError::UnsupportedVersion((42, 1))), matches!(result, ParseError::UnsupportedVersion((42, 1))),
"Unexpected Error type found: {result}" "Unexpected Error type found: {result}"
@ -376,8 +376,8 @@ mod parse_tests {
let tail = [0u8; ELF32_EHDR_TAILSIZE]; let tail = [0u8; ELF32_EHDR_TAILSIZE];
for n in 0..ELF32_EHDR_TAILSIZE { for n in 0..ELF32_EHDR_TAILSIZE {
let buf = tail.split_at(n).0.as_ref(); let buf = tail.split_at(n).0;
let result = FileHeader::parse_tail(ident, &buf).expect_err("Expected an error"); let result = FileHeader::parse_tail(ident, buf).expect_err("Expected an error");
assert!( assert!(
matches!(result, ParseError::SliceReadError(_)), matches!(result, ParseError::SliceReadError(_)),
"Unexpected Error type found: {result:?}" "Unexpected Error type found: {result:?}"
@ -424,7 +424,7 @@ mod parse_tests {
for n in 0..ELF64_EHDR_TAILSIZE { for n in 0..ELF64_EHDR_TAILSIZE {
let buf = tail.split_at(n).0; let buf = tail.split_at(n).0;
let result = FileHeader::parse_tail(ident, &buf).expect_err("Expected an error"); let result = FileHeader::parse_tail(ident, buf).expect_err("Expected an error");
assert!( assert!(
matches!(result, ParseError::SliceReadError(_)), matches!(result, ParseError::SliceReadError(_)),
"Unexpected Error type found: {result:?}" "Unexpected Error type found: {result:?}"

View File

@ -5,7 +5,7 @@ use crate::file::Class;
use crate::parse::{ParseAt, ParseError, ParsingTable}; use crate::parse::{ParseAt, ParseError, ParsingTable};
use crate::string_table::StringTable; use crate::string_table::StringTable;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
pub struct SymbolRequirement<'data> { pub struct SymbolRequirement<'data> {
pub file: &'data str, pub file: &'data str,
pub name: &'data str, pub name: &'data str,
@ -73,7 +73,7 @@ impl<'data, E: EndianParse> SymbolVersionTable<'data, E> {
}; };
let ver_ndx = self.version_ids.get(sym_idx)?; let ver_ndx = self.version_ids.get(sym_idx)?;
let iter = verneeds.clone(); let iter = verneeds;
for (vn, vna_iter) in iter { for (vn, vna_iter) in iter {
for vna in vna_iter { for vna in vna_iter {
if vna.vna_other != ver_ndx.index() { if vna.vna_other != ver_ndx.index() {
@ -113,7 +113,7 @@ impl<'data, E: EndianParse> SymbolVersionTable<'data, E> {
}; };
let ver_ndx = self.version_ids.get(sym_idx)?; let ver_ndx = self.version_ids.get(sym_idx)?;
let iter = verdefs.clone(); let iter = *verdefs;
for (vd, vda_iter) in iter { for (vd, vda_iter) in iter {
if vd.vd_ndx != ver_ndx.index() { if vd.vd_ndx != ver_ndx.index() {
continue; continue;
@ -165,7 +165,7 @@ pub type VersionIndexTable<'data, E> = ParsingTable<'data, E, VersionIndex>;
/// structures in the .gnu.version_d and .gnu.version_r sections. These values /// structures in the .gnu.version_d and .gnu.version_r sections. These values
/// are located in identifiers provided by the the vna_other member of the VerNeedAux /// are located in identifiers provided by the the vna_other member of the VerNeedAux
/// structure or the vd_ndx member of the VerDef structure. /// structure or the vd_ndx member of the VerDef structure.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
pub struct VersionIndex(pub u16); pub struct VersionIndex(pub u16);
impl VersionIndex { impl VersionIndex {
@ -193,9 +193,7 @@ impl ParseAt for VersionIndex {
offset: &mut usize, offset: &mut usize,
data: &[u8], data: &[u8],
) -> Result<Self, ParseError> { ) -> Result<Self, ParseError> {
Ok(VersionIndex { Ok(VersionIndex(endian.parse_u16_at(offset, data)?))
0: endian.parse_u16_at(offset, data)?,
})
} }
#[inline] #[inline]
@ -222,7 +220,7 @@ impl ParseAt for VersionIndex {
/// ///
/// The .gnu.version_d section shall contain an array of VerDef structures /// The .gnu.version_d section shall contain an array of VerDef structures
/// optionally followed by an array of VerDefAux structures. /// optionally followed by an array of VerDefAux structures.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
pub struct VerDef { pub struct VerDef {
/// Version information flag bitmask. /// Version information flag bitmask.
pub vd_flags: u16, pub vd_flags: u16,
@ -303,7 +301,7 @@ impl<'data, E: EndianParse> VerDefIterator<'data, E> {
impl<'data, E: EndianParse> Iterator for VerDefIterator<'data, E> { impl<'data, E: EndianParse> Iterator for VerDefIterator<'data, E> {
type Item = (VerDef, VerDefAuxIterator<'data, E>); type Item = (VerDef, VerDefAuxIterator<'data, E>);
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
if self.data.len() == 0 || self.count == 0 { if self.data.is_empty() || self.count == 0 {
return None; return None;
} }
@ -334,7 +332,7 @@ impl<'data, E: EndianParse> Iterator for VerDefIterator<'data, E> {
} }
/// Version Definition Auxiliary Entries from the .gnu.version_d section /// Version Definition Auxiliary Entries from the .gnu.version_d section
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
pub struct VerDefAux { pub struct VerDefAux {
/// Offset to the version or dependency name string in the linked string table, in bytes. /// Offset to the version or dependency name string in the linked string table, in bytes.
pub vda_name: u32, pub vda_name: u32,
@ -391,7 +389,7 @@ impl<'data, E: EndianParse> VerDefAuxIterator<'data, E> {
impl<'data, E: EndianParse> Iterator for VerDefAuxIterator<'data, E> { impl<'data, E: EndianParse> Iterator for VerDefAuxIterator<'data, E> {
type Item = VerDefAux; type Item = VerDefAux;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
if self.data.len() == 0 || self.count == 0 { if self.data.is_empty() || self.count == 0 {
return None; return None;
} }
@ -457,7 +455,7 @@ impl<'data, E: EndianParse> Iterator for VerDefAuxIterator<'data, E> {
/// ///
/// The section shall contain an array of VerNeed structures optionally /// The section shall contain an array of VerNeed structures optionally
/// followed by an array of VerNeedAux structures. /// followed by an array of VerNeedAux structures.
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
pub struct VerNeed { pub struct VerNeed {
/// Number of associated verneed array entries. /// Number of associated verneed array entries.
pub vn_cnt: u16, pub vn_cnt: u16,
@ -531,7 +529,7 @@ impl<'data, E: EndianParse> VerNeedIterator<'data, E> {
impl<'data, E: EndianParse> Iterator for VerNeedIterator<'data, E> { impl<'data, E: EndianParse> Iterator for VerNeedIterator<'data, E> {
type Item = (VerNeed, VerNeedAuxIterator<'data, E>); type Item = (VerNeed, VerNeedAuxIterator<'data, E>);
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
if self.data.len() == 0 || self.count == 0 { if self.data.is_empty() || self.count == 0 {
return None; return None;
} }
@ -562,7 +560,7 @@ impl<'data, E: EndianParse> Iterator for VerNeedIterator<'data, E> {
} }
/// Version Need Auxiliary Entries from the .gnu.version_r section /// Version Need Auxiliary Entries from the .gnu.version_r section
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq, Eq)]
pub struct VerNeedAux { pub struct VerNeedAux {
/// Dependency name hash value (ELF hash function). /// Dependency name hash value (ELF hash function).
pub vna_hash: u32, pub vna_hash: u32,
@ -584,11 +582,11 @@ impl ParseAt for VerNeedAux {
data: &[u8], data: &[u8],
) -> Result<Self, ParseError> { ) -> Result<Self, ParseError> {
Ok(VerNeedAux { Ok(VerNeedAux {
vna_hash: endian.parse_u32_at(offset, &data)?, vna_hash: endian.parse_u32_at(offset, data)?,
vna_flags: endian.parse_u16_at(offset, &data)?, vna_flags: endian.parse_u16_at(offset, data)?,
vna_other: endian.parse_u16_at(offset, &data)?, vna_other: endian.parse_u16_at(offset, data)?,
vna_name: endian.parse_u32_at(offset, &data)?, vna_name: endian.parse_u32_at(offset, data)?,
vna_next: endian.parse_u32_at(offset, &data)?, vna_next: endian.parse_u32_at(offset, data)?,
}) })
} }
@ -628,7 +626,7 @@ impl<'data, E: EndianParse> VerNeedAuxIterator<'data, E> {
impl<'data, E: EndianParse> Iterator for VerNeedAuxIterator<'data, E> { impl<'data, E: EndianParse> Iterator for VerNeedAuxIterator<'data, E> {
type Item = VerNeedAux; type Item = VerNeedAux;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
if self.data.len() == 0 || self.count == 0 { if self.data.is_empty() || self.count == 0 {
return None; return None;
} }
@ -1178,22 +1176,22 @@ mod parse_tests {
#[test] #[test]
fn parse_verndx32_lsb() { fn parse_verndx32_lsb() {
test_parse_for(LittleEndian, Class::ELF32, VersionIndex { 0: 0x0100 }); test_parse_for(LittleEndian, Class::ELF32, VersionIndex(0x0100));
} }
#[test] #[test]
fn parse_verndx32_msb() { fn parse_verndx32_msb() {
test_parse_for(BigEndian, Class::ELF32, VersionIndex { 0: 0x0001 }); test_parse_for(BigEndian, Class::ELF32, VersionIndex(0x0001));
} }
#[test] #[test]
fn parse_verndx64_lsb() { fn parse_verndx64_lsb() {
test_parse_for(LittleEndian, Class::ELF64, VersionIndex { 0: 0x0100 }); test_parse_for(LittleEndian, Class::ELF64, VersionIndex(0x0100));
} }
#[test] #[test]
fn parse_verndx64_msb() { fn parse_verndx64_msb() {
test_parse_for(BigEndian, Class::ELF64, VersionIndex { 0: 0x0001 }); test_parse_for(BigEndian, Class::ELF64, VersionIndex(0x0001));
} }
#[test] #[test]
@ -1251,7 +1249,7 @@ mod parse_tests {
let mut data = [0u8; ELFVERDEFSIZE]; let mut data = [0u8; ELFVERDEFSIZE];
data[1] = 1; data[1] = 1;
for n in 0..ELFVERDEFSIZE { for n in 0..ELFVERDEFSIZE {
let buf = data.split_at(n).0.as_ref(); let buf = data.split_at(n).0;
let mut offset: usize = 0; let mut offset: usize = 0;
let error = VerDef::parse_at(BigEndian, Class::ELF32, &mut offset, buf) let error = VerDef::parse_at(BigEndian, Class::ELF32, &mut offset, buf)
.expect_err("Expected an error"); .expect_err("Expected an error");
@ -1293,7 +1291,7 @@ mod parse_tests {
let mut data = [0u8; ELFVERDEFSIZE]; let mut data = [0u8; ELFVERDEFSIZE];
data[1] = 1; data[1] = 1;
for n in 0..ELFVERDEFSIZE { for n in 0..ELFVERDEFSIZE {
let buf = data.split_at(n).0.as_ref(); let buf = data.split_at(n).0;
let mut offset: usize = 0; let mut offset: usize = 0;
let error = VerDef::parse_at(BigEndian, Class::ELF64, &mut offset, buf) let error = VerDef::parse_at(BigEndian, Class::ELF64, &mut offset, buf)
.expect_err("Expected an error"); .expect_err("Expected an error");
@ -1422,7 +1420,7 @@ mod parse_tests {
let mut data = [0u8; ELFVERNEEDSIZE]; let mut data = [0u8; ELFVERNEEDSIZE];
data[1] = 1; data[1] = 1;
for n in 0..ELFVERNEEDSIZE { for n in 0..ELFVERNEEDSIZE {
let buf = data.split_at(n).0.as_ref(); let buf = data.split_at(n).0;
let mut offset: usize = 0; let mut offset: usize = 0;
let error = VerNeed::parse_at(BigEndian, Class::ELF32, &mut offset, buf) let error = VerNeed::parse_at(BigEndian, Class::ELF32, &mut offset, buf)
.expect_err("Expected an error"); .expect_err("Expected an error");
@ -1462,7 +1460,7 @@ mod parse_tests {
let mut data = [0u8; ELFVERNEEDSIZE]; let mut data = [0u8; ELFVERNEEDSIZE];
data[1] = 1; data[1] = 1;
for n in 0..ELFVERNEEDSIZE { for n in 0..ELFVERNEEDSIZE {
let buf = data.split_at(n).0.as_ref(); let buf = data.split_at(n).0;
let mut offset: usize = 0; let mut offset: usize = 0;
let error = VerNeed::parse_at(BigEndian, Class::ELF64, &mut offset, buf) let error = VerNeed::parse_at(BigEndian, Class::ELF64, &mut offset, buf)
.expect_err("Expected an error"); .expect_err("Expected an error");

View File

@ -163,7 +163,7 @@ impl ParseAt for u64 {
offset: &mut usize, offset: &mut usize,
data: &[u8], data: &[u8],
) -> Result<Self, ParseError> { ) -> Result<Self, ParseError> {
Ok(endian.parse_u64_at(offset, data)?) endian.parse_u64_at(offset, data)
} }
#[inline] #[inline]

View File

@ -113,13 +113,13 @@ impl<'data> Note<'data> {
abi::NT_GNU_BUILD_ID => Ok(Note::GnuBuildId(NoteGnuBuildId(raw_desc))), abi::NT_GNU_BUILD_ID => Ok(Note::GnuBuildId(NoteGnuBuildId(raw_desc))),
_ => Ok(Note::Unknown(NoteAny { _ => Ok(Note::Unknown(NoteAny {
n_type: nhdr.n_type, n_type: nhdr.n_type,
name: name, name,
desc: raw_desc, desc: raw_desc,
})), })),
}, },
_ => Ok(Note::Unknown(NoteAny { _ => Ok(Note::Unknown(NoteAny {
n_type: nhdr.n_type, n_type: nhdr.n_type,
name: name, name,
desc: raw_desc, desc: raw_desc,
})), })),
} }
@ -201,7 +201,7 @@ impl<'data, E: EndianParse> NoteIterator<'data, E> {
impl<'data, E: EndianParse> Iterator for NoteIterator<'data, E> { impl<'data, E: EndianParse> Iterator for NoteIterator<'data, E> {
type Item = Note<'data>; type Item = Note<'data>;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
if self.data.len() == 0 { if self.data.is_empty() {
return None; return None;
} }
@ -210,7 +210,7 @@ impl<'data, E: EndianParse> Iterator for NoteIterator<'data, E> {
self.class, self.class,
self.align, self.align,
&mut self.offset, &mut self.offset,
&self.data, self.data,
) )
.ok() .ok()
} }

View File

@ -232,7 +232,7 @@ impl<'data, E: EndianParse, P: ParseAt> ParsingIterator<'data, E, P> {
impl<'data, E: EndianParse, P: ParseAt> Iterator for ParsingIterator<'data, E, P> { impl<'data, E: EndianParse, P: ParseAt> Iterator for ParsingIterator<'data, E, P> {
type Item = P; type Item = P;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
if self.data.len() == 0 { if self.data.is_empty() {
return None; return None;
} }
@ -269,7 +269,7 @@ impl<'data, E: EndianParse, P: ParseAt> ParsingTable<'data, E, P> {
} }
pub fn get(&self, index: usize) -> Result<P, ParseError> { pub fn get(&self, index: usize) -> Result<P, ParseError> {
if self.data.len() == 0 { if self.data.is_empty() {
return Err(ParseError::BadOffset(index as u64)); return Err(ParseError::BadOffset(index as u64));
} }
@ -281,7 +281,7 @@ impl<'data, E: EndianParse, P: ParseAt> ParsingTable<'data, E, P> {
return Err(ParseError::BadOffset(index as u64)); return Err(ParseError::BadOffset(index as u64));
} }
Ok(P::parse_at(self.endian, self.class, &mut start, self.data)?) P::parse_at(self.endian, self.class, &mut start, self.data)
} }
} }
@ -301,7 +301,7 @@ impl ParseAt for u32 {
offset: &mut usize, offset: &mut usize,
data: &[u8], data: &[u8],
) -> Result<Self, ParseError> { ) -> Result<Self, ParseError> {
Ok(endian.parse_u32_at(offset, data)?) endian.parse_u32_at(offset, data)
} }
#[inline] #[inline]
@ -353,7 +353,7 @@ pub fn test_parse_fuzz_too_short<E: EndianParse, P: ParseAt + core::fmt::Debug>(
let size = P::size_for(class); let size = P::size_for(class);
let data = vec![0u8; size]; let data = vec![0u8; size];
for n in 0..size { for n in 0..size {
let buf = data.split_at(n).0.as_ref(); let buf = data.split_at(n).0;
let mut offset: usize = 0; let mut offset: usize = 0;
let error = P::parse_at(endian, class, &mut offset, buf).expect_err("Expected an error"); let error = P::parse_at(endian, class, &mut offset, buf).expect_err("Expected an error");
assert!( assert!(

View File

@ -65,7 +65,7 @@ impl ParseAt for ProgramHeader {
p_paddr, p_paddr,
p_filesz, p_filesz,
p_memsz, p_memsz,
p_flags: p_flags, p_flags,
p_align, p_align,
}) })
} }

View File

@ -2,7 +2,7 @@
use crate::parse::ParseError; use crate::parse::ParseError;
use core::str::from_utf8; use core::str::from_utf8;
#[derive(Debug, Clone, Copy)] #[derive(Debug, Default, Clone, Copy)]
pub struct StringTable<'data> { pub struct StringTable<'data> {
data: &'data [u8], data: &'data [u8],
} }
@ -13,7 +13,7 @@ impl<'data> StringTable<'data> {
} }
pub fn get_raw(&self, offset: usize) -> Result<&'data [u8], ParseError> { pub fn get_raw(&self, offset: usize) -> Result<&'data [u8], ParseError> {
if self.data.len() == 0 { if self.data.is_empty() {
return Err(ParseError::BadOffset(offset as u64)); return Err(ParseError::BadOffset(offset as u64));
}; };
@ -35,12 +35,6 @@ impl<'data> StringTable<'data> {
} }
} }
impl<'data> Default for StringTable<'data> {
fn default() -> Self {
StringTable { data: &[] }
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;