mirror of
https://github.com/encounter/objdiff.git
synced 2025-06-07 15:13:47 +00:00
Replace panic! with Option (#25)
This commit is contained in:
parent
ec062bf5ca
commit
6afc535fad
@ -18,12 +18,12 @@ use crate::obj::{
|
|||||||
ObjSymbolFlagSet, ObjSymbolFlags,
|
ObjSymbolFlagSet, ObjSymbolFlags,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn to_obj_section_kind(kind: SectionKind) -> ObjSectionKind {
|
fn to_obj_section_kind(kind: SectionKind) -> Option<ObjSectionKind> {
|
||||||
match kind {
|
match kind {
|
||||||
SectionKind::Text => ObjSectionKind::Code,
|
SectionKind::Text => Some(ObjSectionKind::Code),
|
||||||
SectionKind::Data | SectionKind::ReadOnlyData => ObjSectionKind::Data,
|
SectionKind::Data | SectionKind::ReadOnlyData => Some(ObjSectionKind::Data),
|
||||||
SectionKind::UninitializedData => ObjSectionKind::Bss,
|
SectionKind::UninitializedData => Some(ObjSectionKind::Bss),
|
||||||
_ => panic!("Unhandled section kind {kind:?}"),
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,18 +74,14 @@ fn filter_sections(obj_file: &File<'_>) -> Result<Vec<ObjSection>> {
|
|||||||
if section.size() == 0 {
|
if section.size() == 0 {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if section.kind() != SectionKind::Text
|
let Some(kind) = to_obj_section_kind(section.kind()) else {
|
||||||
&& section.kind() != SectionKind::Data
|
|
||||||
&& section.kind() != SectionKind::ReadOnlyData
|
|
||||||
&& section.kind() != SectionKind::UninitializedData
|
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
};
|
||||||
let name = section.name().context("Failed to process section name")?;
|
let name = section.name().context("Failed to process section name")?;
|
||||||
let data = section.uncompressed_data().context("Failed to read section data")?;
|
let data = section.uncompressed_data().context("Failed to read section data")?;
|
||||||
result.push(ObjSection {
|
result.push(ObjSection {
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
kind: to_obj_section_kind(section.kind()),
|
kind,
|
||||||
address: section.address(),
|
address: section.address(),
|
||||||
size: section.size(),
|
size: section.size(),
|
||||||
data: data.to_vec(),
|
data: data.to_vec(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user