From a5a6a3928e392d5af5d92826e73b77e074b8788c Mon Sep 17 00:00:00 2001 From: Aetias <144526980+AetiasHax@users.noreply.github.com> Date: Tue, 4 Jun 2024 03:47:38 +0200 Subject: [PATCH] Fix read error on objects with no .text section (#67) * Fix read error on objects with no .text section * Fix read error on DWARF 1.1 objects * Revert DWARF 1 changes --------- Co-authored-by: Luke Street --- objdiff-core/src/obj/read.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/objdiff-core/src/obj/read.rs b/objdiff-core/src/obj/read.rs index 86f0025..9b75923 100644 --- a/objdiff-core/src/obj/read.rs +++ b/objdiff-core/src/obj/read.rs @@ -328,15 +328,10 @@ fn line_info(obj_file: &File<'_>, sections: &mut [ObjSection]) -> Result<()> { if let Some(program) = unit.line_program.clone() { let mut text_sections = obj_file.sections().filter(|s| s.kind() == SectionKind::Text); - let section_index = text_sections - .next() - .ok_or_else(|| anyhow!("Next text section not found for line info"))? - .index() - .0; - let mut lines = sections - .iter_mut() - .find(|s| s.orig_index == section_index) - .map(|s| &mut s.line_info); + let section_index = text_sections.next().map(|s| s.index().0); + let mut lines = section_index.map(|index| { + &mut sections.iter_mut().find(|s| s.orig_index == index).unwrap().line_info + }); let mut rows = program.rows(); while let Some((_header, row)) = rows.next_row()? {