From 3ea9c4eb4eef2949b2fc41065cb00f187e3d564d Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Sun, 12 Jan 2025 23:59:46 -0500 Subject: [PATCH] Misc clippy lints and clippy CI Co-authored-by: Michael Krasnitski --- .github/workflows/rust.yml | 17 ++++++++++++++++- rust/build.rs | 2 +- rust/examples/workflow.rs | 25 +++++++++++-------------- rust/src/architecture.rs | 1 + rust/src/basicblock.rs | 2 +- rust/src/binaryview.rs | 2 +- rust/src/component.rs | 3 --- rust/src/confidence.rs | 2 +- rust/src/databuffer.rs | 2 +- rust/src/demangle.rs | 7 ++----- rust/src/disassembly.rs | 2 +- rust/src/enterprise.rs | 3 +++ rust/src/flowgraph.rs | 4 ++-- rust/src/hlil/instruction.rs | 2 +- rust/src/lib.rs | 3 ++- rust/src/llil/block.rs | 10 ++++++---- rust/src/llil/function.rs | 27 +++++++++++++++------------ rust/src/mlil/instruction.rs | 2 +- rust/src/project.rs | 2 +- rust/src/section.rs | 2 +- rust/src/settings.rs | 4 ---- rust/src/typearchive.rs | 2 +- rust/src/typecontainer.rs | 2 +- rust/src/typeprinter.rs | 10 +++------- rust/src/types.rs | 8 +++++--- rust/src/variable.rs | 6 ++++-- rust/src/workflow.rs | 20 ++++---------------- rust/tests/databuffer.rs | 2 +- 28 files changed, 87 insertions(+), 87 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index dcab7247d..0f643de73 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -10,8 +10,23 @@ on: - 'rust/**' jobs: - # TODO: Cargo clippy (just warnings don't fail) # TODO: Cargo test (we would need to pull in binary ninja) + # Check lints with clippy + clippy: + name: cargo clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # Ensure clippy is installed + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: clippy + - name: Clippy Check + - uses: clechasseur/rs-clippy-check@v4 + with: + working-directory: ./rust + args: --all-features + # Check formatting with rustfmt formatting: name: cargo fmt diff --git a/rust/build.rs b/rust/build.rs index 18983aee9..46b518e00 100644 --- a/rust/build.rs +++ b/rust/build.rs @@ -5,7 +5,7 @@ fn main() { let _ = std::fs::create_dir("target/doc"); let _ = std::fs::copy("../docs/img/favicon.ico", "target/doc/favicon.ico"); let _ = std::fs::copy( - "under_construction.png", + "assets/under_construction.png", "target/doc/under_construction.png", ); let _ = std::fs::copy("../docs/img/logo.png", "target/doc/logo.png"); diff --git a/rust/examples/workflow.rs b/rust/examples/workflow.rs index 6722ba680..60e7e2c0a 100644 --- a/rust/examples/workflow.rs +++ b/rust/examples/workflow.rs @@ -2,8 +2,8 @@ use binaryninja::binaryview::BinaryViewExt; use binaryninja::llil::{ExprInfo, LiftedNonSSA, NonSSA, VisitorAction}; use binaryninja::workflow::{Activity, AnalysisContext, Workflow}; -const RUST_ACTIVITY_NAME: &'static str = "analysis.plugins.rustexample"; -const RUST_ACTIVITY_CONFIG: &'static str = r#"{ +const RUST_ACTIVITY_NAME: &str = "analysis.plugins.rustexample"; +const RUST_ACTIVITY_CONFIG: &str = r#"{ "name": "analysis.plugins.rustexample", "title" : "Rust Example", "description": "This analysis step logs out some information about the function...", @@ -27,18 +27,15 @@ fn example_activity(analysis_context: &AnalysisContext) { for instr in basic_block.iter() { if let Some(llil_instr) = llil.instruction_at(instr) { llil_instr.visit_tree(&mut |expr, info| { - match info { - ExprInfo::Const(_op) => { - // Replace all consts with 0x1337. - println!( - "Replacing llil expression @ 0x{:x} : {}", - instr, expr.index - ); - unsafe { - llil.replace_expression(expr.index, llil.const_int(4, 0x1337)) - }; - } - _ => {} + if let ExprInfo::Const(_op) = info { + // Replace all consts with 0x1337. + println!( + "Replacing llil expression @ 0x{:x} : {}", + instr, expr.index + ); + unsafe { + llil.replace_expression(expr.index, llil.const_int(4, 0x1337)) + }; } VisitorAction::Descend }); diff --git a/rust/src/architecture.rs b/rust/src/architecture.rs index 43a41bab5..2fbd3cb43 100644 --- a/rust/src/architecture.rs +++ b/rust/src/architecture.rs @@ -200,6 +200,7 @@ impl From for InstructionInfo { fn from(value: BNInstructionInfo) -> Self { // TODO: This is quite ugly, but we destructure the branch info so this will have to do. let mut branch_info = [None; NUM_BRANCH_INFO]; + #[allow(clippy::needless_range_loop)] for i in 0..value.branchCount.min(NUM_BRANCH_INFO) { let branch_target = value.branchTarget[i]; branch_info[i] = Some(BranchInfo { diff --git a/rust/src/basicblock.rs b/rust/src/basicblock.rs index 56ff0abeb..96406fd11 100644 --- a/rust/src/basicblock.rs +++ b/rust/src/basicblock.rs @@ -240,7 +240,7 @@ impl BasicBlock { // TODO iterated dominance frontier } -impl<'a, C: BlockContext> IntoIterator for &'a BasicBlock { +impl IntoIterator for &BasicBlock { type Item = C::Instruction; type IntoIter = C::Iter; diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs index 7909e8d5e..6a9246fb7 100644 --- a/rust/src/binaryview.rs +++ b/rust/src/binaryview.rs @@ -678,7 +678,7 @@ pub trait BinaryViewExt: BinaryViewBase { let name_array = unsafe { Array::::new(result_names, result_count, ()) }; id_array .into_iter() - .zip(name_array.into_iter()) + .zip(&name_array) .map(|(id, name)| (id.to_owned(), name)) .collect() } diff --git a/rust/src/component.rs b/rust/src/component.rs index 7ed514509..b705e3093 100644 --- a/rust/src/component.rs +++ b/rust/src/component.rs @@ -146,13 +146,10 @@ impl Component { } /// Original name set for this component - /// :note: The `.display_name` property should be used for `bv.get_component_by_path()` lookups. - /// This can differ from the .display_name property if one of its sibling components has the same .original_name; In that /// case, .name will be an automatically generated unique name (e.g. "MyComponentName (1)") while .original_name will /// remain what was originally set (e.g. "MyComponentName") - /// If this component has a duplicate name and is moved to a component where none of its siblings share its name, /// .name will return the original "MyComponentName" pub fn name(&self) -> BnString { diff --git a/rust/src/confidence.rs b/rust/src/confidence.rs index 5a23c88b5..792e46be0 100644 --- a/rust/src/confidence.rs +++ b/rust/src/confidence.rs @@ -189,7 +189,7 @@ impl From for Conf { } } -impl<'a> Conf<&'a Type> { +impl Conf<&'_ Type> { pub(crate) fn into_raw(value: Self) -> BNTypeWithConfidence { BNTypeWithConfidence { type_: value.contents.handle, diff --git a/rust/src/databuffer.rs b/rust/src/databuffer.rs index 3bc833b23..5b4d6515a 100644 --- a/rust/src/databuffer.rs +++ b/rust/src/databuffer.rs @@ -172,7 +172,7 @@ impl DataBuffer { impl Default for DataBuffer { fn default() -> Self { - Self(unsafe { BNCreateDataBuffer([].as_ptr() as *const c_void, 0) }) + Self(unsafe { BNCreateDataBuffer([].as_ptr(), 0) }) } } diff --git a/rust/src/demangle.rs b/rust/src/demangle.rs index 43d30133b..3a3d924dd 100644 --- a/rust/src/demangle.rs +++ b/rust/src/demangle.rs @@ -301,10 +301,7 @@ impl Demangler { }) } - extern "C" fn cb_free_var_name(_ctxt: *mut c_void, name: *mut BNQualifiedName) - where - C: CustomDemangler, - { + extern "C" fn cb_free_var_name(_ctxt: *mut c_void, name: *mut BNQualifiedName) { ffi_wrap!("CustomDemangler::cb_free_var_name", unsafe { // TODO: What is the point of this free callback? QualifiedName::free_raw(*name) @@ -319,7 +316,7 @@ impl Demangler { context: ctxt as *mut c_void, isMangledString: Some(cb_is_mangled_string::), demangle: Some(cb_demangle::), - freeVarName: Some(cb_free_var_name::), + freeVarName: Some(cb_free_var_name), }; unsafe { diff --git a/rust/src/disassembly.rs b/rust/src/disassembly.rs index cb4b9cfea..99938e5fd 100644 --- a/rust/src/disassembly.rs +++ b/rust/src/disassembly.rs @@ -263,7 +263,7 @@ impl InstructionTextToken { let kind_value = value.kind.try_value().unwrap_or(0); let operand = value.kind.try_operand().unwrap_or(0); let size = value.kind.try_size().unwrap_or(0); - let type_names = value.kind.try_type_names().unwrap_or(vec![]); + let type_names = value.kind.try_type_names().unwrap_or_default(); BNInstructionTextToken { type_: value.kind.into(), // NOTE: Expected to be freed with `InstructionTextToken::free_raw`. diff --git a/rust/src/enterprise.rs b/rust/src/enterprise.rs index adb1a32a6..092733843 100644 --- a/rust/src/enterprise.rs +++ b/rust/src/enterprise.rs @@ -20,6 +20,7 @@ pub fn checkout_license(duration: Duration) -> Result<(), EnterpriseCheckoutErro return Ok(()); } + #[allow(clippy::collapsible_if)] if !is_server_initialized() { if !initialize_server() && is_server_floating_license() { return Err(EnterpriseCheckoutError(server_last_error().to_string())); @@ -31,6 +32,7 @@ pub fn checkout_license(duration: Duration) -> Result<(), EnterpriseCheckoutErro return Err(EnterpriseCheckoutError(server_last_error().to_string())); } + #[allow(clippy::collapsible_if)] if !is_server_authenticated() { if !authenticate_server_with_method("Keychain", false) { let Some(username) = std::env::var("BN_ENTERPRISE_USERNAME").ok() else { @@ -50,6 +52,7 @@ pub fn checkout_license(duration: Duration) -> Result<(), EnterpriseCheckoutErro } } + #[allow(clippy::collapsible_if)] if !is_server_license_still_activated() || (!is_server_floating_license() && crate::license_expiration_time() < SystemTime::now()) { diff --git a/rust/src/flowgraph.rs b/rust/src/flowgraph.rs index 36f66c732..d7d873d95 100644 --- a/rust/src/flowgraph.rs +++ b/rust/src/flowgraph.rs @@ -92,7 +92,7 @@ impl<'a> FlowGraphNode<'a> { } } -unsafe impl<'a> RefCountable for FlowGraphNode<'a> { +unsafe impl RefCountable for FlowGraphNode<'_> { unsafe fn inc_ref(handle: &Self) -> Ref { Ref::new(Self { handle: BNNewFlowGraphNodeReference(handle.handle), @@ -105,7 +105,7 @@ unsafe impl<'a> RefCountable for FlowGraphNode<'a> { } } -impl<'a> ToOwned for FlowGraphNode<'a> { +impl ToOwned for FlowGraphNode<'_> { type Owned = Ref; fn to_owned(&self) -> Self::Owned { diff --git a/rust/src/hlil/instruction.rs b/rust/src/hlil/instruction.rs index 664faf3c3..b114f02ba 100644 --- a/rust/src/hlil/instruction.rs +++ b/rust/src/hlil/instruction.rs @@ -754,7 +754,7 @@ impl HighLevelILInstruction { // TODO: Replace with a From for RegisterValueType. // TODO: We might also want to change the type of `op.constant_data_kind` // TODO: To RegisterValueType and do the conversion when creating instruction. - state: unsafe { std::mem::transmute(op.constant_data_kind) }, + state: unsafe { std::mem::transmute::(op.constant_data_kind) }, value: op.constant_data_value, offset: 0, size: op.size, diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 23d690b86..5e55e6722 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -16,6 +16,7 @@ #![allow(clippy::missing_safety_doc)] #![allow(clippy::result_unit_err)] #![allow(clippy::type_complexity)] +#![allow(clippy::too_many_arguments)] #![doc(html_root_url = "https://dev-rust.binary.ninja/")] #![doc(html_favicon_url = "/favicon.ico")] #![doc(html_logo_url = "/logo.png")] @@ -211,7 +212,7 @@ unsafe extern "C" fn cb_progress_func bool>( if ctxt.is_null() { return true; } - let closure: &mut F = std::mem::transmute(ctxt); + let closure = &mut *(ctxt as *mut F); closure(progress, total) } diff --git a/rust/src/llil/block.rs b/rust/src/llil/block.rs index 9068bb7a3..da3215785 100644 --- a/rust/src/llil/block.rs +++ b/rust/src/llil/block.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::fmt::Debug; use std::ops::Range; use crate::architecture::Architecture; @@ -78,15 +79,16 @@ where } } -impl<'func, A, M, F> fmt::Debug for LowLevelILBlock<'func, A, M, F> +impl<'func, A, M, F> Debug for LowLevelILBlock<'func, A, M, F> where - A: 'func + Architecture, + A: 'func + Architecture + Debug, M: FunctionMutability, F: FunctionForm, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - // TODO: Make this better - write!(f, "llil_bb {:?}", self.function) + f.debug_struct("LowLevelILBlock") + .field("function", &self.function) + .finish() } } diff --git a/rust/src/llil/function.rs b/rust/src/llil/function.rs index cd1f8e39c..cdb8744fe 100644 --- a/rust/src/llil/function.rs +++ b/rust/src/llil/function.rs @@ -18,6 +18,7 @@ use binaryninjacore_sys::BNLowLevelILFunction; use binaryninjacore_sys::BNNewLowLevelILFunctionReference; use std::borrow::Borrow; +use std::fmt::Debug; use std::hash::{Hash, Hasher}; use std::marker::PhantomData; @@ -63,9 +64,9 @@ pub struct LowLevelILFunction, } -impl<'func, A, M, F> LowLevelILFunction +impl LowLevelILFunction where - A: 'func + Architecture, + A: Architecture, M: FunctionMutability, F: FunctionForm, { @@ -137,9 +138,9 @@ where // LLIL basic blocks are not available until the function object // is finalized, so ensure we can't try requesting basic blocks // during lifting -impl<'func, A, F> LowLevelILFunction +impl LowLevelILFunction where - A: 'func + Architecture, + A: Architecture, F: FunctionForm, { pub fn basic_blocks(&self) -> Array>> { @@ -176,9 +177,9 @@ impl LowLevelILFunction> { } } -impl<'func, A, M, F> ToOwned for LowLevelILFunction +impl ToOwned for LowLevelILFunction where - A: 'func + Architecture, + A: Architecture, M: FunctionMutability, F: FunctionForm, { @@ -189,9 +190,9 @@ where } } -unsafe impl<'func, A, M, F> RefCountable for LowLevelILFunction +unsafe impl RefCountable for LowLevelILFunction where - A: 'func + Architecture, + A: Architecture, M: FunctionMutability, F: FunctionForm, { @@ -210,15 +211,17 @@ where } } -impl<'func, A, M, F> fmt::Debug for LowLevelILFunction +impl Debug for LowLevelILFunction where - A: 'func + Architecture, + A: Architecture + Debug, M: FunctionMutability, F: FunctionForm, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - // TODO: Make this better - write!(f, "", self.handle) + f.debug_struct("LowLevelILFunction") + .field("arch", &self.arch()) + .field("instruction_count", &self.instruction_count()) + .finish() } } diff --git a/rust/src/mlil/instruction.rs b/rust/src/mlil/instruction.rs index 47f76566c..6892d7176 100644 --- a/rust/src/mlil/instruction.rs +++ b/rust/src/mlil/instruction.rs @@ -753,7 +753,7 @@ impl MediumLevelILInstruction { // TODO: Replace with a From for RegisterValueType. // TODO: We might also want to change the type of `op.constant_data_kind` // TODO: To RegisterValueType and do the conversion when creating instruction. - state: unsafe { std::mem::transmute(op.constant_data_kind) }, + state: unsafe { std::mem::transmute::(op.constant_data_kind) }, value: op.constant_data_value, offset: 0, size: op.size, diff --git a/rust/src/project.rs b/rust/src/project.rs index 45e3a2b82..edea8b234 100644 --- a/rust/src/project.rs +++ b/rust/src/project.rs @@ -1103,7 +1103,7 @@ unsafe extern "C" fn cb_progress_func bool>( if ctxt.is_null() { return true; } - let closure: &mut F = mem::transmute(ctxt); + let closure = &mut *(ctxt as *mut F); closure(progress, total) } diff --git a/rust/src/section.rs b/rust/src/section.rs index cf66c3f99..7df3d014d 100644 --- a/rust/src/section.rs +++ b/rust/src/section.rs @@ -273,7 +273,7 @@ impl SectionBuilder { let len = self.range.end.wrapping_sub(start); unsafe { - let nul_str = std::ffi::CStr::from_bytes_with_nul_unchecked(b"\x00").as_ptr(); + let nul_str = c"".as_ptr(); let name_ptr = name.as_ref().as_ptr() as *mut _; let ty_ptr = ty.map_or(nul_str, |s| s.as_ref().as_ptr() as *mut _); let linked_section_ptr = diff --git a/rust/src/settings.rs b/rust/src/settings.rs index 0c9fd7877..f37a5a348 100644 --- a/rust/src/settings.rs +++ b/rust/src/settings.rs @@ -50,10 +50,6 @@ impl Settings { } } - pub fn default() -> Ref { - Self::new("default") - } - pub fn set_resource_id(&self, resource_id: S) { let resource_id = resource_id.into_bytes_with_nul(); unsafe { BNSettingsSetResourceId(self.handle, resource_id.as_ref().as_ptr() as *mut _) }; diff --git a/rust/src/typearchive.rs b/rust/src/typearchive.rs index 3060a4798..058c6f446 100644 --- a/rust/src/typearchive.rs +++ b/rust/src/typearchive.rs @@ -376,7 +376,7 @@ impl TypeArchive { } /// Get a list of all types' names and ids in the archive at a current snapshot - + /// /// * `snapshot` - Snapshot id to search for types pub fn get_type_names_and_ids( &self, diff --git a/rust/src/typecontainer.rs b/rust/src/typecontainer.rs index 3acb79747..341a44796 100644 --- a/rust/src/typecontainer.rs +++ b/rust/src/typecontainer.rs @@ -351,7 +351,7 @@ impl TypeContainer { /// Parse an entire block of source into types, variables, and functions, with /// knowledge of the types in the Type Container. - + /// /// * `source` - Source code to parse /// * `file_name` - Name of the file containing the source (optional: exists on disk) /// * `options` - String arguments to pass as options, e.g. command line arguments diff --git a/rust/src/typeprinter.rs b/rust/src/typeprinter.rs index 44fb3173b..e9c36f967 100644 --- a/rust/src/typeprinter.rs +++ b/rust/src/typeprinter.rs @@ -365,12 +365,8 @@ impl CoreTypePrinter { impl Default for CoreTypePrinter { fn default() -> Self { // TODO: Remove this entirely, there is no "default", its view specific lets not make this some defined behavior. - let default_settings = crate::settings::Settings::default(); - let name = default_settings.get_string( - std::ffi::CStr::from_bytes_with_nul(b"analysis.types.printerName\x00").unwrap(), - None, - None, - ); + let default_settings = crate::settings::Settings::new("default"); + let name = default_settings.get_string("analysis.types.printerName", None, None); Self::printer_by_name(name).unwrap() } } @@ -931,7 +927,7 @@ unsafe extern "C" fn cb_print_all_types( let ctxt: &mut T = &mut *(ctxt as *mut T); let raw_names = std::slice::from_raw_parts(names, type_count); // NOTE: The caller is responsible for freeing raw_names. - let names: Vec<_> = raw_names.into_iter().map(QualifiedName::from_raw).collect(); + let names: Vec<_> = raw_names.iter().map(QualifiedName::from_raw).collect(); let raw_types = std::slice::from_raw_parts(types, type_count); // NOTE: The caller is responsible for freeing raw_types. let types: Vec<_> = raw_types.iter().map(|&t| Type::ref_from_raw(t)).collect(); diff --git a/rust/src/types.rs b/rust/src/types.rs index cccde1bc2..ff5f67b97 100644 --- a/rust/src/types.rs +++ b/rust/src/types.rs @@ -339,7 +339,7 @@ impl TypeBuilder { pub fn named_type_from_type>(name: T, t: &Type) -> Self { let mut raw_name = QualifiedName::into_raw(name.into()); - let id = CStr::from_bytes_with_nul(b"\0").unwrap(); + let id = c""; let result = unsafe { Self::from_raw(BNCreateNamedTypeReferenceBuilderFromTypeAndId( @@ -726,7 +726,7 @@ impl Type { pub fn named_type_from_type>(name: T, t: &Type) -> Ref { let mut raw_name = QualifiedName::into_raw(name.into()); // TODO: No id is present for this call? - let id = CStr::from_bytes_with_nul(b"\0").unwrap(); + let id = c""; let result = unsafe { Self::ref_from_raw(BNCreateNamedTypeReferenceFromTypeAndId( @@ -1124,6 +1124,7 @@ impl FunctionParameter { } } +// TODO: We need to delete this... // Name, Variable and Type impl CoreArrayProvider for (&str, Variable, &Type) { type Raw = BNVariableNameAndType; @@ -1134,6 +1135,7 @@ impl CoreArrayProvider for (&str, Variable, &Type) { Self: 'a; } +// TODO: This needs to go! unsafe impl CoreArrayProviderInner for (&str, Variable, &Type) { unsafe fn free(raw: *mut Self::Raw, count: usize, _context: &Self::Context) { BNFreeVariableNameAndTypeList(raw, count) @@ -1145,7 +1147,7 @@ unsafe impl CoreArrayProviderInner for (&str, Variable, &Type) { ) -> (&'a str, Variable, &'a Type) { let name = CStr::from_ptr(raw.name).to_str().unwrap(); let var = Variable::from(raw.var); - let var_type = std::mem::transmute(&raw.type_); + let var_type = &*(raw.type_ as *mut Type); (name, var, var_type) } } diff --git a/rust/src/variable.rs b/rust/src/variable.rs index e868663ee..e0bbc2f43 100644 --- a/rust/src/variable.rs +++ b/rust/src/variable.rs @@ -739,8 +739,10 @@ impl PossibleValueSet { } pub(crate) fn into_raw(value: Self) -> BNPossibleValueSet { - let mut raw = BNPossibleValueSet::default(); - raw.state = value.value_type(); + let mut raw = BNPossibleValueSet { + state: value.value_type(), + ..Default::default() + }; match value { PossibleValueSet::UndeterminedValue => {} PossibleValueSet::EntryValue { reg } => { diff --git a/rust/src/workflow.rs b/rust/src/workflow.rs index 236e0cb73..f8042ccc7 100644 --- a/rust/src/workflow.rs +++ b/rust/src/workflow.rs @@ -192,7 +192,7 @@ impl Activity { ctxt: *mut c_void, analysis: *mut BNAnalysisContext, ) { - let ctxt: &mut F = core::mem::transmute(ctxt); + let ctxt = &mut *(ctxt as *mut F); if let Some(analysis) = NonNull::new(analysis) { ctxt(&AnalysisContext::from_raw(analysis)) } @@ -567,29 +567,17 @@ impl Workflow { /// Not yet implemented. pub fn show_metrics(&self) { - unsafe { - BNWorkflowShowReport( - self.handle.as_ptr(), - b"metrics\x00".as_ptr() as *const c_char, - ) - } + unsafe { BNWorkflowShowReport(self.handle.as_ptr(), c"metrics".as_ptr()) } } /// Show the Workflow topology in the UI. pub fn show_topology(&self) { - unsafe { - BNWorkflowShowReport( - self.handle.as_ptr(), - b"topology\x00".as_ptr() as *const c_char, - ) - } + unsafe { BNWorkflowShowReport(self.handle.as_ptr(), c"topology".as_ptr()) } } /// Not yet implemented. pub fn show_trace(&self) { - unsafe { - BNWorkflowShowReport(self.handle.as_ptr(), b"trace\x00".as_ptr() as *const c_char) - } + unsafe { BNWorkflowShowReport(self.handle.as_ptr(), c"trace".as_ptr()) } } } diff --git a/rust/tests/databuffer.rs b/rust/tests/databuffer.rs index 631748a36..441210b6e 100644 --- a/rust/tests/databuffer.rs +++ b/rust/tests/databuffer.rs @@ -22,7 +22,7 @@ fn set_len_write() { // and is not using the original pointer contents.as_mut_slice().fill(0x55); drop(contents); - assert_eq!(data.get_data(), &DUMMY_DATA_0[..]); + assert_eq!(data.get_data(), DUMMY_DATA_0); // make sure the new len truncate the original data unsafe { data.set_len(13) };