Skip to content

Commit 32ca34a

Browse files
committed
[Rust] Misc cleanup regarding c strings
1 parent 2b334df commit 32ca34a

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

rust/src/function.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ use crate::variable::{
4848
StackVariableReference, Variable,
4949
};
5050
use crate::workflow::Workflow;
51+
use std::ffi::CStr;
5152
use std::fmt::{Debug, Formatter};
5253
use std::ptr::NonNull;
5354
use std::time::Duration;
54-
use std::{ffi::c_char, hash::Hash, ops::Range};
55+
use std::{hash::Hash, ops::Range};
5556

5657
/// Used to describe a location within a [`Function`].
5758
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
@@ -2213,17 +2214,17 @@ impl Function {
22132214
///
22142215
/// * `name` - Name of the debug report
22152216
pub fn request_debug_report(&self, name: &str) {
2216-
const DEBUG_REPORT_ALIAS: &[(&str, &str)] = &[
2217-
("stack", "stack_adjust_graph\x00"),
2218-
("mlil", "mlil_translator\x00"),
2219-
("hlil", "high_level_il\x00"),
2217+
const DEBUG_REPORT_ALIAS: &[(&str, &CStr)] = &[
2218+
("stack", c"stack_adjust_graph"),
2219+
("mlil", c"mlil_translator"),
2220+
("hlil", c"high_level_il"),
22202221
];
22212222

22222223
if let Some(alias_idx) = DEBUG_REPORT_ALIAS
22232224
.iter()
22242225
.position(|(alias, _value)| *alias == name)
22252226
{
2226-
let name = DEBUG_REPORT_ALIAS[alias_idx].1.as_ptr() as *const c_char;
2227+
let name = DEBUG_REPORT_ALIAS[alias_idx].1.as_ptr();
22272228
unsafe { BNRequestFunctionDebugReport(self.handle, name) }
22282229
} else {
22292230
let name = std::ffi::CString::new(name.to_string()).unwrap();

rust/src/interaction/report.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::ffi::c_char;
21
use std::ptr::NonNull;
32

43
use binaryninjacore_sys::*;
@@ -81,8 +80,8 @@ impl ReportCollection {
8180
BNAddPlainTextReportToCollection(
8281
self.handle.as_ptr(),
8382
view.handle,
84-
title.as_ref().as_ptr() as *const c_char,
85-
contents.as_ref().as_ptr() as *const c_char,
83+
title.as_ptr(),
84+
contents.as_ptr(),
8685
)
8786
}
8887
}
@@ -95,9 +94,9 @@ impl ReportCollection {
9594
BNAddMarkdownReportToCollection(
9695
self.handle.as_ptr(),
9796
view.handle,
98-
title.as_ref().as_ptr() as *const c_char,
99-
contents.as_ref().as_ptr() as *const c_char,
100-
plaintext.as_ref().as_ptr() as *const c_char,
97+
title.as_ptr(),
98+
contents.as_ptr(),
99+
plaintext.as_ptr(),
101100
)
102101
}
103102
}
@@ -110,9 +109,9 @@ impl ReportCollection {
110109
BNAddHTMLReportToCollection(
111110
self.handle.as_ptr(),
112111
view.handle,
113-
title.as_ref().as_ptr() as *const c_char,
114-
contents.as_ref().as_ptr() as *const c_char,
115-
plaintext.as_ref().as_ptr() as *const c_char,
112+
title.as_ptr(),
113+
contents.as_ptr(),
114+
plaintext.as_ptr(),
116115
)
117116
}
118117
}
@@ -123,7 +122,7 @@ impl ReportCollection {
123122
BNAddGraphReportToCollection(
124123
self.handle.as_ptr(),
125124
view.handle,
126-
title.as_ref().as_ptr() as *const c_char,
125+
title.as_ptr(),
127126
graph.handle,
128127
)
129128
}

0 commit comments

Comments
 (0)