From 788a8b7091bbdde77817030e0836d7a7a786fd99 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sun, 4 May 2025 19:47:55 -0400 Subject: [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. --- rust/src/external_library.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'rust/src/external_library.rs') 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(&self, symbol: Option) -> 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()) + }, + } } } -- cgit v1.3.1