From 0af300011820ba28fde1ae8da8ae5a47c1c805ca Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Thu, 22 Aug 2024 19:33:14 -0400 Subject: Use add/sub with overflow when rebasing, fix crash. Found this while testing some MSP430 binaries with the new support being added. I had the logic correct, but forgot to tell Rust that overflow was expected. --- rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'rust') diff --git a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs index 3e5cc1bf..d7ffb8c1 100644 --- a/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs +++ b/rust/examples/dwarf/dwarf_import/src/dwarfdebuginfo.rs @@ -533,8 +533,8 @@ impl DebugInfoBuilder { } if let Some(address) = func.address.as_mut() { - let diff = bv.start() - bv.original_image_base(); - *address += diff; // rebase the address + let diff = bv.start().overflowing_sub(bv.original_image_base()).0; + *address = (*address).overflowing_add(diff).0; // rebase the address let existing_functions = bv.functions_at(*address); match existing_functions.len().cmp(&1) { Ordering::Greater => { -- cgit v1.3.1