Skip to content

Commit 6039d8f

Browse files
authored
Some minor cleanup (#383)
* fix a typo * minor clean up
1 parent 9a0673e commit 6039d8f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/symbolize/gimli.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ cfg_if::cfg_if! {
208208
target_os = "watchos",
209209
))] {
210210
// macOS uses the Mach-O file format and uses DYLD-specific APIs to
211-
// load a list of native libraries that are part of the appplication.
211+
// load a list of native libraries that are part of the application.
212212

213213
use mystd::os::unix::prelude::*;
214214
use mystd::ffi::{OsStr, CStr};
@@ -372,28 +372,32 @@ cfg_if::cfg_if! {
372372
fn native_libraries() -> Vec<Library> {
373373
let mut ret = Vec::new();
374374
unsafe {
375-
libc::dl_iterate_phdr(Some(callback), &mut ret as *mut _ as *mut _);
375+
libc::dl_iterate_phdr(Some(callback), &mut ret as *mut Vec<_> as *mut _);
376376
}
377377
return ret;
378378
}
379379

380+
// `info` should be a valid pointers.
381+
// `vec` should be a valid pointer to a `std::Vec`.
380382
unsafe extern "C" fn callback(
381383
info: *mut libc::dl_phdr_info,
382384
_size: libc::size_t,
383385
vec: *mut libc::c_void,
384386
) -> libc::c_int {
387+
let info = &*info;
385388
let libs = &mut *(vec as *mut Vec<Library>);
386-
let name = if (*info).dlpi_name.is_null() || *(*info).dlpi_name == 0{
389+
let is_main_prog = info.dlpi_name.is_null() || *info.dlpi_name == 0;
390+
let name = if is_main_prog {
387391
if libs.is_empty() {
388392
mystd::env::current_exe().map(|e| e.into()).unwrap_or_default()
389393
} else {
390394
OsString::new()
391395
}
392396
} else {
393-
let bytes = CStr::from_ptr((*info).dlpi_name).to_bytes();
397+
let bytes = CStr::from_ptr(info.dlpi_name).to_bytes();
394398
OsStr::from_bytes(bytes).to_owned()
395399
};
396-
let headers = core::slice::from_raw_parts((*info).dlpi_phdr, (*info).dlpi_phnum as usize);
400+
let headers = core::slice::from_raw_parts(info.dlpi_phdr, info.dlpi_phnum as usize);
397401
libs.push(Library {
398402
name,
399403
segments: headers
@@ -403,7 +407,7 @@ cfg_if::cfg_if! {
403407
stated_virtual_memory_address: (*header).p_vaddr as usize,
404408
})
405409
.collect(),
406-
bias: (*info).dlpi_addr as usize,
410+
bias: info.dlpi_addr as usize,
407411
});
408412
0
409413
}

0 commit comments

Comments
 (0)