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/logger.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'rust/src/logger.rs') diff --git a/rust/src/logger.rs b/rust/src/logger.rs index c06f4dfc..5f14af69 100644 --- a/rust/src/logger.rs +++ b/rust/src/logger.rs @@ -35,7 +35,7 @@ use binaryninjacore_sys::{ }; use crate::rc::{Ref, RefCountable}; -use crate::string::BnString; +use crate::string::{AsCStr, BnString}; use log; use log::LevelFilter; use std::ffi::{CStr, CString}; @@ -139,12 +139,12 @@ impl log::Log for Ref { if let Ok(msg) = CString::new(format!("{}", record.args())) { let percent_s = CString::new("%s").expect("'%s' has no null bytes"); - let logger_name = self.name(); + let logger_name = self.name().to_cstr(); unsafe { BNLog( self.session_id(), level, - logger_name.as_ptr() as *const c_char, + logger_name.as_ptr(), 0, percent_s.as_ptr(), msg.as_ptr(), -- cgit v1.3.1