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/architecture.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'rust/src/architecture.rs') diff --git a/rust/src/architecture.rs b/rust/src/architecture.rs index 74a8dfa4..62693800 100644 --- a/rust/src/architecture.rs +++ b/rust/src/architecture.rs @@ -1404,7 +1404,8 @@ impl CoreArchitecture { } pub fn by_name(name: &str) -> Option { - let handle = unsafe { BNGetArchitectureByName(name.to_cstr().as_ptr() as *mut _) }; + let name = name.to_cstr(); + let handle = unsafe { BNGetArchitectureByName(name.as_ptr()) }; match handle.is_null() { false => Some(CoreArchitecture { handle }), true => None, @@ -1955,9 +1956,7 @@ pub trait ArchitectureExt: Architecture { fn register_by_name(&self, name: S) -> Option { let name = name.to_cstr(); - match unsafe { - BNGetArchitectureRegisterByName(self.as_ref().handle, name.as_ref().as_ptr() as *mut _) - } { + match unsafe { BNGetArchitectureRegisterByName(self.as_ref().handle, name.as_ptr()) } { 0xffff_ffff => None, reg => self.register_from_id(reg.into()), } @@ -3220,8 +3219,7 @@ where }; unsafe { - let res = - BNRegisterArchitecture(name.as_ref().as_ptr() as *mut _, &mut custom_arch as *mut _); + let res = BNRegisterArchitecture(name.as_ptr(), &mut custom_arch as *mut _); assert!(!res.is_null()); -- cgit v1.3.1