diff --git a/src/analysis/executor.rs b/src/analysis/executor.rs index fbcb0b1..5e0dc47 100644 --- a/src/analysis/executor.rs +++ b/src/analysis/executor.rs @@ -18,7 +18,7 @@ struct VisitedAddresses { impl VisitedAddresses { pub fn new(obj: &ObjInfo) -> Self { - let mut inner = Vec::with_capacity(obj.sections.count()); + let mut inner = Vec::with_capacity(obj.sections.len()); for (_, section) in obj.sections.iter() { if section.kind == ObjSectionKind::Code { let size = (section.size / 4) as usize; diff --git a/src/obj/sections.rs b/src/obj/sections.rs index 6c0f4bf..61d45c6 100644 --- a/src/obj/sections.rs +++ b/src/obj/sections.rs @@ -51,7 +51,9 @@ impl ObjSections { self.sections.iter_mut().enumerate() } - pub fn count(&self) -> usize { self.sections.len() } + pub fn len(&self) -> usize { self.sections.len() } + + pub fn is_empty(&self) -> bool { self.sections.is_empty() } pub fn next_section_index(&self) -> usize { self.sections.len() } diff --git a/src/util/config.rs b/src/util/config.rs index db76e00..d3e78f4 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -652,7 +652,7 @@ where R: BufRead + ?Sized { "Section out of bounds: {} (index {}), object has {} sections", name, index, - obj.sections.count() + obj.sections.len() ); }; if obj_section.rename(name.clone()).is_err() { diff --git a/src/util/elf.rs b/src/util/elf.rs index 95a8022..62d470e 100644 --- a/src/util/elf.rs +++ b/src/util/elf.rs @@ -396,7 +396,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result> { } writer.reserve_null_section_index(); - let mut out_sections: Vec = Vec::with_capacity(obj.sections.count()); + let mut out_sections: Vec = Vec::with_capacity(obj.sections.len()); for (_, section) in obj.sections.iter() { let name = writer.add_section_name(section.name.as_bytes()); let index = writer.reserve_section_index(); @@ -411,7 +411,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result> { }); } - let mut rela_names: Vec = vec![Default::default(); obj.sections.count()]; + let mut rela_names: Vec = vec![Default::default(); obj.sections.len()]; for (((_, section), out_section), rela_name) in obj.sections.iter().zip(&mut out_sections).zip(&mut rela_names) { @@ -630,7 +630,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result> { writer.reserve_file_header(); if obj.kind == ObjKind::Executable { - writer.reserve_program_headers(obj.sections.count() as u32); + writer.reserve_program_headers(obj.sections.len() as u32); } for ((_, section), out_section) in obj.sections.iter().zip(&mut out_sections) { diff --git a/src/util/split.rs b/src/util/split.rs index 8d274f4..18dff1b 100644 --- a/src/util/split.rs +++ b/src/util/split.rs @@ -710,7 +710,7 @@ fn trim_split_alignment(obj: &mut ObjInfo) -> Result<()> { /// Trim splits if they contain linker generated symbols. fn trim_linker_generated_symbols(obj: &mut ObjInfo) -> Result<()> { - for section_index in 0..obj.sections.count() { + for section_index in 0..obj.sections.len() { let section_end = end_for_section(obj, section_index)?; let section = &mut obj.sections[section_index]; if section.address as u32 + section.size as u32 == section_end.address {