Skip to content

Commit e28a9f9

Browse files
committed
Replace panic! with Option
1 parent c7b6ec8 commit e28a9f9

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

src/obj/elf.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ use crate::obj::{
1717
ObjSymbolFlagSet, ObjSymbolFlags,
1818
};
1919

20-
fn to_obj_section_kind(kind: SectionKind) -> ObjSectionKind {
20+
fn to_obj_section_kind(kind: SectionKind) -> Option<ObjSectionKind> {
2121
match kind {
22-
SectionKind::Text => ObjSectionKind::Code,
23-
SectionKind::Data | SectionKind::ReadOnlyData => ObjSectionKind::Data,
24-
SectionKind::UninitializedData => ObjSectionKind::Bss,
25-
_ => panic!("Unhandled section kind {kind:?}"),
22+
SectionKind::Text => Some(ObjSectionKind::Code),
23+
SectionKind::Data | SectionKind::ReadOnlyData => Some(ObjSectionKind::Data),
24+
SectionKind::UninitializedData => Some(ObjSectionKind::Bss),
25+
_ => None,
2626
}
2727
}
2828

@@ -73,18 +73,14 @@ fn filter_sections(obj_file: &File<'_>) -> Result<Vec<ObjSection>> {
7373
if section.size() == 0 {
7474
continue;
7575
}
76-
if section.kind() != SectionKind::Text
77-
&& section.kind() != SectionKind::Data
78-
&& section.kind() != SectionKind::ReadOnlyData
79-
&& section.kind() != SectionKind::UninitializedData
80-
{
76+
let Some(kind) = to_obj_section_kind(section.kind()) else {
8177
continue;
82-
}
78+
};
8379
let name = section.name().context("Failed to process section name")?;
8480
let data = section.uncompressed_data().context("Failed to read section data")?;
8581
result.push(ObjSection {
8682
name: name.to_string(),
87-
kind: to_obj_section_kind(section.kind()),
83+
kind,
8884
address: section.address(),
8985
size: section.size(),
9086
data: data.to_vec(),

0 commit comments

Comments
 (0)