Skip to content

Commit b77df77

Browse files
committed
Minor cleanup, remove Section::symbol_data
1 parent 7e08f97 commit b77df77

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

objdiff-core/src/arch/superh/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ impl Arch for ArchSuperH {
7676

7777
sh2_disasm(0, opcode, true, &mut parts, &resolved, &mut branch_dest);
7878

79-
if let Some(symbol_data) = resolved.section.symbol_data(resolved.symbol) {
79+
if let Some(symbol_data) =
80+
resolved.section.data_range(resolved.symbol.address, resolved.symbol.size as usize)
81+
{
8082
// scan for data
8183
// map of instruction offsets to data target offsets
8284
let mut data_offsets = BTreeMap::<u64, DataInfo>::new();

objdiff-core/src/obj/mod.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,8 @@ impl fmt::Debug for SectionData {
9999

100100
impl Section {
101101
pub fn data_range(&self, address: u64, size: usize) -> Option<&[u8]> {
102-
let start = self.address;
103-
let end = start + self.size;
104-
if address >= start && address + size as u64 <= end {
105-
let offset = (address - start) as usize;
106-
Some(&self.data[offset..offset + size])
107-
} else {
108-
None
109-
}
110-
}
111-
112-
pub fn symbol_data(&self, symbol: &Symbol) -> Option<&[u8]> {
113-
let offset = symbol.address.checked_sub(self.address)?;
114-
self.data.get(offset as usize..offset as usize + symbol.size as usize)
102+
let offset = address.checked_sub(self.address)?;
103+
self.data.get(offset as usize..offset as usize + size)
115104
}
116105

117106
// The alignment to use when "Combine data/text sections" is enabled.

objdiff-core/src/util.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,5 @@ pub fn align_data_to_4<W: std::io::Write + ?Sized>(
5757
pub fn align_u64_to(len: u64, align: u64) -> u64 { len + ((align - (len % align)) % align) }
5858

5959
pub fn align_data_slice_to(data: &mut Vec<u8>, align: u64) {
60-
const ALIGN_BYTE: u8 = 0;
61-
data.resize(align_u64_to(data.len() as u64, align) as usize, ALIGN_BYTE);
60+
data.resize(align_u64_to(data.len() as u64, align) as usize, 0);
6261
}

0 commit comments

Comments
 (0)