diff options
| author | Rubens Brandao <git@rubens.io> | 2024-04-17 09:35:12 -0300 |
|---|---|---|
| committer | Rubens Brandao <git@rubens.io> | 2024-04-17 09:41:58 -0300 |
| commit | 9717866665a42356881b062fcd80bc09492ee8b8 (patch) | |
| tree | 3deda26aa66d55689eaf1333b67fceed0631b27a /rust/src/relocation.rs | |
| parent | f408eb32085956f7e29e0f15fd92aa4b72453370 (diff) | |
remove unecessary and crash causing zeroed call inits
Diffstat (limited to 'rust/src/relocation.rs')
| -rw-r--r-- | rust/src/relocation.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/rust/src/relocation.rs b/rust/src/relocation.rs index f9cbb3c5..c56b2a4e 100644 --- a/rust/src/relocation.rs +++ b/rust/src/relocation.rs @@ -8,6 +8,7 @@ use crate::{ }; use binaryninjacore_sys::*; use std::borrow::Borrow; +use std::mem::MaybeUninit; use std::os::raw::c_void; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -501,12 +502,9 @@ where let name = name.into_bytes_with_nul(); - let uninit_handler = RelocationHandlerBuilder { - handler: unsafe { std::mem::zeroed() }, - }; - let raw = Box::into_raw(Box::new(uninit_handler)); + let raw = Box::leak(Box::new(MaybeUninit::<RelocationHandlerBuilder<_>>::zeroed())); let mut custom_handler = BNCustomRelocationHandler { - context: raw as *mut _, + context: raw.as_mut_ptr() as *mut _, freeObject: Some(cb_free::<R>), getRelocationInfo: Some(cb_get_relocation_info::<R>), applyRelocation: Some(cb_apply_relocation::<R>), @@ -517,13 +515,12 @@ where assert!(!handle_raw.is_null()); let handle = CoreRelocationHandler(handle_raw); let custom_handle = CustomRelocationHandlerHandle { - handle: raw as *mut R, + handle: raw.as_mut_ptr() as *mut R, }; unsafe { - core::ptr::write( - &mut raw.as_mut().unwrap().handler, - func(custom_handle, CoreRelocationHandler(handle.0)), - ); + raw.write(RelocationHandlerBuilder { + handler: func(custom_handle, CoreRelocationHandler(handle.0)), + }); BNArchitectureRegisterRelocationHandler( arch.handle().as_ref().0, |
