summaryrefslogtreecommitdiff
path: root/rust/src/relocation.rs
diff options
context:
space:
mode:
authorRyan Snyder <ryan@vector35.com>2024-05-01 08:33:43 -0400
committerRyan Snyder <ryan@vector35.com>2024-05-01 08:33:43 -0400
commit3ccfedef84b8743f7045c50cdeb3f78b530ada8d (patch)
treecc4850291d5cff7005de9e68b43b98c322ab2fb2 /rust/src/relocation.rs
parent2fb7daaf3210c4984f20444560145e776b586601 (diff)
parent9717866665a42356881b062fcd80bc09492ee8b8 (diff)
Merge branch 'remove-zeroed-init' of github.com:rbran/binaryninja-api into dev
Diffstat (limited to 'rust/src/relocation.rs')
-rw-r--r--rust/src/relocation.rs17
1 files changed, 7 insertions, 10 deletions
diff --git a/rust/src/relocation.rs b/rust/src/relocation.rs
index 455f5a5a..17fd5958 100644
--- a/rust/src/relocation.rs
+++ b/rust/src/relocation.rs
@@ -9,6 +9,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)]
@@ -502,12 +503,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>),
@@ -518,13 +516,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,