diff options
| author | Mason Reed <mason@vector35.com> | 2025-05-04 19:47:55 -0400 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2025-05-12 17:45:24 -0400 |
| commit | 788a8b7091bbdde77817030e0836d7a7a786fd99 (patch) | |
| tree | 40e8f8d3c870788259a5acb5d14995cdc1656979 /rust/src/collaboration/merge.rs | |
| parent | a826c589dfc10c542deba7ca3343a462e02d6bde (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/collaboration/merge.rs')
| -rw-r--r-- | rust/src/collaboration/merge.rs | 27 |
1 files changed, 6 insertions, 21 deletions
diff --git a/rust/src/collaboration/merge.rs b/rust/src/collaboration/merge.rs index 84aa6192..2fb5b3de 100644 --- a/rust/src/collaboration/merge.rs +++ b/rust/src/collaboration/merge.rs @@ -1,5 +1,4 @@ use binaryninjacore_sys::*; -use std::ffi::c_char; use std::ptr::NonNull; use crate::database::{snapshot::Snapshot, Database}; @@ -52,10 +51,7 @@ impl MergeConflict { pub fn path_item_string<S: AsCStr>(&self, path: S) -> Result<BnString, ()> { let path = path.to_cstr(); let result = unsafe { - BNAnalysisMergeConflictGetPathItemString( - self.handle.as_ptr(), - path.as_ref().as_ptr() as *const c_char, - ) + BNAnalysisMergeConflictGetPathItemString(self.handle.as_ptr(), path.as_ptr()) }; (!result.is_null()) .then(|| unsafe { BnString::from_raw(result) }) @@ -125,24 +121,16 @@ impl MergeConflict { /// Call this when you've resolved the conflict to save the result pub fn success<S: AsCStr>(&self, value: S) -> Result<(), ()> { let value = value.to_cstr(); - let success = unsafe { - BNAnalysisMergeConflictSuccess( - self.handle.as_ptr(), - value.as_ref().as_ptr() as *const c_char, - ) - }; + let success = + unsafe { BNAnalysisMergeConflictSuccess(self.handle.as_ptr(), value.as_ptr()) }; success.then_some(()).ok_or(()) } // TODO: Make a safe version of this that checks the path and if it holds a number pub unsafe fn get_path_item_number<S: AsCStr>(&self, path_key: S) -> Option<u64> { let path_key = path_key.to_cstr(); - let value = unsafe { - BNAnalysisMergeConflictGetPathItem( - self.handle.as_ptr(), - path_key.as_ref().as_ptr() as *const c_char, - ) - }; + let value = + unsafe { BNAnalysisMergeConflictGetPathItem(self.handle.as_ptr(), path_key.as_ptr()) }; match value.is_null() { // SAFETY: The path must be a number. false => Some(value as u64), @@ -153,10 +141,7 @@ impl MergeConflict { pub unsafe fn get_path_item_string<S: AsCStr>(&self, path_key: S) -> Option<BnString> { let path_key = path_key.to_cstr(); let value = unsafe { - BNAnalysisMergeConflictGetPathItemString( - self.handle.as_ptr(), - path_key.as_ref().as_ptr() as *const c_char, - ) + BNAnalysisMergeConflictGetPathItemString(self.handle.as_ptr(), path_key.as_ptr()) }; match value.is_null() { false => Some(unsafe { BnString::from_raw(value) }), |
