Skip to content

Commit 7d48c7a

Browse files
committed
Cargo Clippy
1 parent 7f107e9 commit 7d48c7a

3 files changed

Lines changed: 22 additions & 27 deletions

File tree

crates/delink-macho/src/lib.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -267,28 +267,26 @@ fn parse_stubs_32(data: &[u8]) -> Result<HashMap<u64, String>> {
267267
u32::from_le_bytes(data[pos + 60..pos + 64].try_into().unwrap());
268268
}
269269
}
270-
LC_SEGMENT => {
271-
if cmdsize >= SEGMENT_CMD32_SIZE {
272-
// nsects at offset 48 within segment_command_32
273-
let nsects =
274-
u32::from_le_bytes(data[pos + 48..pos + 52].try_into().unwrap()) as usize;
275-
for i in 0..nsects {
276-
let sec_base = pos + SEGMENT_CMD32_SIZE + i * SECTION32_SIZE;
277-
if sec_base + SECTION32_SIZE > cmds_end {
278-
break;
279-
}
280-
let sec = &data[sec_base..sec_base + SECTION32_SIZE];
281-
// section_32: addr[32..36] size[36..40] flags[56..60]
282-
// reserved1[60..64] reserved2[64..68]
283-
let flags = u32::from_le_bytes(sec[56..60].try_into().unwrap());
284-
if flags & SECTION_TYPE == S_SYMBOL_STUBS {
285-
let addr = u32::from_le_bytes(sec[32..36].try_into().unwrap()) as u64;
286-
let size = u32::from_le_bytes(sec[36..40].try_into().unwrap()) as u64;
287-
let reserved1 = u32::from_le_bytes(sec[60..64].try_into().unwrap());
288-
let reserved2 = u32::from_le_bytes(sec[64..68].try_into().unwrap());
289-
if reserved2 > 0 && size > 0 {
290-
stub_secs.push((addr, size, reserved1, reserved2));
291-
}
270+
LC_SEGMENT if cmdsize >= SEGMENT_CMD32_SIZE => {
271+
// nsects at offset 48 within segment_command_32
272+
let nsects =
273+
u32::from_le_bytes(data[pos + 48..pos + 52].try_into().unwrap()) as usize;
274+
for i in 0..nsects {
275+
let sec_base = pos + SEGMENT_CMD32_SIZE + i * SECTION32_SIZE;
276+
if sec_base + SECTION32_SIZE > cmds_end {
277+
break;
278+
}
279+
let sec = &data[sec_base..sec_base + SECTION32_SIZE];
280+
// section_32: addr[32..36] size[36..40] flags[56..60]
281+
// reserved1[60..64] reserved2[64..68]
282+
let flags = u32::from_le_bytes(sec[56..60].try_into().unwrap());
283+
if flags & SECTION_TYPE == S_SYMBOL_STUBS {
284+
let addr = u32::from_le_bytes(sec[32..36].try_into().unwrap()) as u64;
285+
let size = u32::from_le_bytes(sec[36..40].try_into().unwrap()) as u64;
286+
let reserved1 = u32::from_le_bytes(sec[60..64].try_into().unwrap());
287+
let reserved2 = u32::from_le_bytes(sec[64..68].try_into().unwrap());
288+
if reserved2 > 0 && size > 0 {
289+
stub_secs.push((addr, size, reserved1, reserved2));
292290
}
293291
}
294292
}

crates/delink-macho/src/symtab_json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ fn sanitize_filename(name: &str) -> String {
369369
}
370370
})
371371
.collect();
372-
let trimmed = s.trim_start_matches(|c: char| c == '.' || c == '_');
372+
let trimmed = s.trim_start_matches(['.', '_']);
373373
let truncated = &trimmed[..trimmed.len().min(200)];
374374
if truncated.is_empty() {
375375
"unknown".to_string()

crates/delink-macho/src/symtab_split.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ pub fn build_cu_index_from_symtab(data: &[u8]) -> Result<MachoCuIndex> {
7979

8080
// Group into batches and build CUs.
8181
let mut units = Vec::new();
82-
let mut cu_id = 0usize;
83-
8482
for (batch_idx, batch) in fns.chunks(BATCH_SIZE).enumerate() {
8583
let batch_start = batch_idx * BATCH_SIZE;
8684
let functions: Vec<MachoFunction> = batch
@@ -104,15 +102,14 @@ pub fn build_cu_index_from_symtab(data: &[u8]) -> Result<MachoCuIndex> {
104102
let cu_name = functions[0].name.clone();
105103

106104
units.push(MachoCompilationUnit {
107-
id: cu_id,
105+
id: batch_idx,
108106
name: cu_name,
109107
comp_dir: None,
110108
oso_path: None,
111109
ranges,
112110
functions,
113111
variables: vec![],
114112
});
115-
cu_id += 1;
116113
}
117114

118115
Ok(MachoCuIndex { units })

0 commit comments

Comments
 (0)