Skip to content

Commit 6ff8d00

Browse files
authored
Fix panic when parsing DWARF 2 line info for empty section (#125)
* Fix panic when parsing DWARF 2 line info for empty section * Fix panic when parsing DWARF 2 line info for empty section May as well remove both unwraps :p
1 parent 9ca157d commit 6ff8d00

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

objdiff-core/src/obj/read.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,9 @@ fn line_info(obj_file: &File<'_>, sections: &mut [ObjSection], obj_data: &[u8])
431431
let mut text_sections =
432432
obj_file.sections().filter(|s| s.kind() == SectionKind::Text);
433433
let section_index = text_sections.next().map(|s| s.index().0);
434-
let mut lines = section_index.map(|index| {
435-
&mut sections.iter_mut().find(|s| s.orig_index == index).unwrap().line_info
436-
});
434+
let mut lines = section_index
435+
.and_then(|index| sections.iter_mut().find(|s| s.orig_index == index))
436+
.map(|s| &mut s.line_info);
437437

438438
let mut rows = program.rows();
439439
while let Some((_header, row)) = rows.next_row()? {
@@ -444,13 +444,9 @@ fn line_info(obj_file: &File<'_>, sections: &mut [ObjSection], obj_data: &[u8])
444444
// The next row is the start of a new sequence, which means we must
445445
// advance to the next .text section.
446446
let section_index = text_sections.next().map(|s| s.index().0);
447-
lines = section_index.map(|index| {
448-
&mut sections
449-
.iter_mut()
450-
.find(|s| s.orig_index == index)
451-
.unwrap()
452-
.line_info
453-
});
447+
lines = section_index
448+
.and_then(|index| sections.iter_mut().find(|s| s.orig_index == index))
449+
.map(|s| &mut s.line_info);
454450
}
455451
}
456452
}

0 commit comments

Comments
 (0)