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
This commit is contained in:
Aetias 2024-10-19 17:39:18 +02:00 committed by GitHub
parent 9ca157d717
commit 6ff8d002f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 10 deletions

View File

@ -431,9 +431,9 @@ fn line_info(obj_file: &File<'_>, sections: &mut [ObjSection], obj_data: &[u8])
let mut text_sections = let mut text_sections =
obj_file.sections().filter(|s| s.kind() == SectionKind::Text); obj_file.sections().filter(|s| s.kind() == SectionKind::Text);
let section_index = text_sections.next().map(|s| s.index().0); let section_index = text_sections.next().map(|s| s.index().0);
let mut lines = section_index.map(|index| { let mut lines = section_index
&mut sections.iter_mut().find(|s| s.orig_index == index).unwrap().line_info .and_then(|index| sections.iter_mut().find(|s| s.orig_index == index))
}); .map(|s| &mut s.line_info);
let mut rows = program.rows(); let mut rows = program.rows();
while let Some((_header, row)) = rows.next_row()? { while let Some((_header, row)) = rows.next_row()? {
@ -444,13 +444,9 @@ fn line_info(obj_file: &File<'_>, sections: &mut [ObjSection], obj_data: &[u8])
// The next row is the start of a new sequence, which means we must // The next row is the start of a new sequence, which means we must
// advance to the next .text section. // advance to the next .text section.
let section_index = text_sections.next().map(|s| s.index().0); let section_index = text_sections.next().map(|s| s.index().0);
lines = section_index.map(|index| { lines = section_index
&mut sections .and_then(|index| sections.iter_mut().find(|s| s.orig_index == index))
.iter_mut() .map(|s| &mut s.line_info);
.find(|s| s.orig_index == index)
.unwrap()
.line_info
});
} }
} }
} }