diff options
| author | Josh Ferrell <josh@vector35.com> | 2024-07-05 12:15:21 -0400 |
|---|---|---|
| committer | Josh Ferrell <josh@vector35.com> | 2024-07-05 12:20:33 -0400 |
| commit | 0dc909f1800296619053e067a1e3700665f4644c (patch) | |
| tree | 5851a0791c03e7e5fce55f8ba6da3910f0e6e988 /rust/examples/dwarf/dwarf_import/src/helpers.rs | |
| parent | 98db31c6f2442aac6b3d6687e0200fa61acc8d3b (diff) | |
Fix crash when parsing enums from zig dwarf info
Diffstat (limited to 'rust/examples/dwarf/dwarf_import/src/helpers.rs')
| -rw-r--r-- | rust/examples/dwarf/dwarf_import/src/helpers.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/rust/examples/dwarf/dwarf_import/src/helpers.rs b/rust/examples/dwarf/dwarf_import/src/helpers.rs index 14de90bf..09465d82 100644 --- a/rust/examples/dwarf/dwarf_import/src/helpers.rs +++ b/rust/examples/dwarf/dwarf_import/src/helpers.rs @@ -260,14 +260,20 @@ pub(crate) fn get_start_address<R: Reader<Offset = usize>>( // Get an attribute value as a u64 if it can be coerced pub(crate) fn get_attr_as_u64<R: Reader<Offset = usize>>(attr: &Attribute<R>) -> Option<u64> { - if let Some(value) = attr.u8_value() { - Some(value.into()) - } else if let Some(value) = attr.u16_value() { - Some(value.into()) - } else if let Some(value) = attr.udata_value() { + if let Some(value) = attr.udata_value() { Some(value) + } else if let Some(value) = attr.sdata_value() { + Some(value as u64) + } else if let Some(mut expr) = attr.exprloc_value() { + match expr.0.len() { + 1 => expr.0.read_u8().map(u64::from).ok(), + 2 => expr.0.read_u16().map(u64::from).ok(), + 4 => expr.0.read_u32().map(u64::from).ok(), + 8 => expr.0.read_u64().ok(), + _ => None + } } else { - attr.sdata_value().map(|value| value as u64) + None } } |
