summaryrefslogtreecommitdiff
path: root/rust/src/external_library.rs
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-05-04 19:47:55 -0400
committerMason Reed <35282038+emesare@users.noreply.github.com>2025-05-12 17:45:24 -0400
commit788a8b7091bbdde77817030e0836d7a7a786fd99 (patch)
tree40e8f8d3c870788259a5acb5d14995cdc1656979 /rust/src/external_library.rs
parenta826c589dfc10c542deba7ca3343a462e02d6bde (diff)
[Rust] Simplify usage surrounding c strings
`cstring.as_ref().as_ptr() as *const c_char` -> `cstring.as_ptr()` `cstring.as_ref().as_ptr() as *mut _` -> `cstring.as_ptr()` `cstring.as_ptr() as *const c_char` -> `cstring.as_ptr()` With a few fixes for cstrings that might be dropped prematurely.
Diffstat (limited to 'rust/src/external_library.rs')
-rw-r--r--rust/src/external_library.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/rust/src/external_library.rs b/rust/src/external_library.rs
index 26425ccd..57848a7a 100644
--- a/rust/src/external_library.rs
+++ b/rust/src/external_library.rs
@@ -3,7 +3,6 @@ use crate::rc::{CoreArrayProvider, CoreArrayProviderInner, Guard, Ref, RefCounta
use crate::string::{AsCStr, BnString};
use crate::symbol::Symbol;
use binaryninjacore_sys::*;
-use std::ffi::c_char;
use std::fmt::Debug;
use std::ptr::NonNull;
@@ -168,10 +167,15 @@ impl ExternalLocation {
/// Set the symbol pointed to by this ExternalLocation.
/// ExternalLocations must have a valid target address and/or symbol set.
pub fn set_target_symbol<S: AsCStr>(&self, symbol: Option<S>) -> bool {
- let symbol = symbol
- .map(|x| x.to_cstr().as_ref().as_ptr() as *const c_char)
- .unwrap_or(std::ptr::null_mut());
- unsafe { BNExternalLocationSetTargetSymbol(self.handle.as_ptr(), symbol) }
+ match symbol {
+ Some(sym) => {
+ let raw_sym = sym.to_cstr();
+ unsafe { BNExternalLocationSetTargetSymbol(self.handle.as_ptr(), raw_sym.as_ptr()) }
+ }
+ None => unsafe {
+ BNExternalLocationSetTargetSymbol(self.handle.as_ptr(), std::ptr::null())
+ },
+ }
}
}