Skip to content

Commit 6546844

Browse files
committed
[Rust] Fix misc clippy lints and warnings
These are introduced after changing to Rust 1.91.1
1 parent 6eb12c3 commit 6546844

File tree

17 files changed

+56
-57
lines changed

17 files changed

+56
-57
lines changed

arch/msp430/src/flag.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub enum Flag {
1616
impl architecture::Flag for Flag {
1717
type FlagClass = FlagClass;
1818

19-
fn name(&self) -> Cow<str> {
19+
fn name(&self) -> Cow<'_, str> {
2020
match self {
2121
Self::C => "c".into(),
2222
Self::Z => "z".into(),
@@ -62,7 +62,7 @@ impl TryFrom<FlagId> for Flag {
6262
pub struct FlagClass {}
6363

6464
impl architecture::FlagClass for FlagClass {
65-
fn name(&self) -> Cow<str> {
65+
fn name(&self) -> Cow<'_, str> {
6666
unimplemented!()
6767
}
6868

@@ -78,7 +78,7 @@ impl architecture::FlagGroup for FlagGroup {
7878
type FlagType = Flag;
7979
type FlagClass = FlagClass;
8080

81-
fn name(&self) -> Cow<str> {
81+
fn name(&self) -> Cow<'_, str> {
8282
unimplemented!()
8383
}
8484

@@ -107,7 +107,7 @@ impl architecture::FlagWrite for FlagWrite {
107107
type FlagType = Flag;
108108
type FlagClass = FlagClass;
109109

110-
fn name(&self) -> Cow<str> {
110+
fn name(&self) -> Cow<'_, str> {
111111
match self {
112112
Self::All => "*".into(),
113113
Self::Nz => "nz".into(),

arch/riscv/disasm/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,7 @@ pub enum Instr<D: RiscVDisassembler> {
17751775
}
17761776

17771777
impl<D: RiscVDisassembler> Instr<D> {
1778-
pub fn mnem(&self) -> Mnem<D> {
1778+
pub fn mnem(&self) -> Mnem<'_, D> {
17791779
Mnem(self)
17801780
}
17811781

@@ -2116,7 +2116,7 @@ impl<'a, D: RiscVDisassembler + 'a> Mnem<'a, D> {
21162116
}
21172117
}
21182118

2119-
fn suffix(&self) -> Option<Cow<str>> {
2119+
fn suffix(&self) -> Option<Cow<'_, str>> {
21202120
match self.0 {
21212121
// &Instr::Rv16(_) => None,
21222122
&Instr::Rv32(ref op) | &Instr::Rv16(ref op) => match *op {

arch/riscv/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl<D: RiscVDisassembler> RegisterInfo for Register<D> {
169169
impl<D: RiscVDisassembler> architecture::Register for Register<D> {
170170
type InfoType = Self;
171171

172-
fn name(&self) -> Cow<str> {
172+
fn name(&self) -> Cow<'_, str> {
173173
match self.reg_type() {
174174
RegType::Integer(id) => match id {
175175
0 => "zero".into(),
@@ -393,7 +393,7 @@ impl<D: RiscVDisassembler> From<Intrinsic> for RiscVIntrinsic<D> {
393393
}
394394

395395
impl<D: RiscVDisassembler> architecture::Intrinsic for RiscVIntrinsic<D> {
396-
fn name(&self) -> Cow<str> {
396+
fn name(&self) -> Cow<'_, str> {
397397
match self.id {
398398
Intrinsic::Uret => "_uret".into(),
399399
Intrinsic::Sret => "_sret".into(),

plugins/idb_import/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ pub fn translate_til_types(
630630
arch: CoreArchitecture,
631631
til: &TILSection,
632632
progress: impl Fn(usize, usize) -> Result<(), ()>,
633-
) -> Result<Vec<TranslatesIDBType>> {
633+
) -> Result<Vec<TranslatesIDBType<'_>>> {
634634
let total = til.symbols.len() + til.types.len();
635635
let mut types = Vec::with_capacity(total);
636636
let mut types_by_ord = HashMap::with_capacity(total);

plugins/warp/src/cache/type_reference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn cached_type_reference(
3939
}
4040
}
4141

42-
pub fn cached_type_references(view: &BinaryView) -> Option<Ref<ViewID, TypeRefCache>> {
42+
pub fn cached_type_references(view: &BinaryView) -> Option<Ref<'_, ViewID, TypeRefCache>> {
4343
let view_id = ViewID::from(view);
4444
let type_ref_cache = TYPE_REF_CACHE.get_or_init(Default::default);
4545
type_ref_cache.get(&view_id)

plugins/warp/src/convert/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ pub fn to_bn_calling_convention<A: BNArchitecture>(
281281

282282
// Always pass the architecture unless you know what you're doing!
283283
pub fn to_bn_type<A: BNArchitecture + Copy>(arch: Option<A>, ty: &Type) -> BNRef<BNType> {
284-
let bits_to_bytes = |val: u64| (val / 8);
284+
let bits_to_bytes = |val: u64| val / 8;
285285
let addr_size = arch.map(|a| a.address_size()).unwrap_or(8) as u64;
286286
match &ty.class {
287287
TypeClass::Void => BNType::void(),

plugins/warp/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pub fn basic_block_guid<M: FunctionMutability>(
254254
pub fn filtered_instructions_at<M: FunctionMutability>(
255255
il: &LowLevelILFunction<M, NonSSA>,
256256
addr: u64,
257-
) -> Vec<LowLevelILInstruction<M, NonSSA>> {
257+
) -> Vec<LowLevelILInstruction<'_, M, NonSSA>> {
258258
il.instructions_at(addr)
259259
.into_iter()
260260
.enumerate()

plugins/warp/src/plugin.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use log::LevelFilter;
1919

2020
mod commit;
2121
mod create;
22-
mod debug;
2322
mod ffi;
2423
mod file;
2524
mod function;
@@ -29,6 +28,9 @@ mod render_layer;
2928
mod settings;
3029
mod workflow;
3130

31+
#[cfg(debug_assertions)]
32+
mod debug;
33+
3234
fn load_bundled_signatures() {
3335
let global_bn_settings = Settings::new();
3436
let plugin_settings =

rust/src/base_detection.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use binaryninjacore_sys::*;
2-
use std::ffi::{c_char, CStr};
2+
use std::ffi::CStr;
33

44
use crate::architecture::CoreArchitecture;
55
use crate::rc::{Array, CoreArrayProvider, CoreArrayProviderInner};
6+
use crate::string::IntoCStr;
67
use std::num::NonZeroU32;
78
use std::ptr::NonNull;
89

@@ -11,7 +12,7 @@ pub type BaseAddressDetectionConfidence = BNBaseAddressDetectionConfidence;
1112
pub type BaseAddressDetectionPOIType = BNBaseAddressDetectionPOIType;
1213

1314
/// This is the architecture name used to use the architecture auto-detection feature.
14-
const BASE_ADDRESS_AUTO_DETECTION_ARCH: &CStr = c"auto detect";
15+
const BASE_ADDRESS_AUTO_DETECTION_ARCH: &str = "auto detect";
1516

1617
pub enum BaseAddressDetectionAnalysis {
1718
Basic,
@@ -149,34 +150,34 @@ impl Drop for BaseAddressDetection {
149150
}
150151
}
151152

152-
/// Build the initial analysis.
153-
///
154-
/// * `analysis` - analysis mode
155-
/// * `min_strlen` - minimum length of a string to be considered a point-of-interest
156-
/// * `alignment` - byte boundary to align the base address to while brute-forcing
157-
/// * `low_boundary` - lower boundary of the base address range to test
158-
/// * `high_boundary` - upper boundary of the base address range to test
159-
/// * `poi_analysis` - specifies types of points-of-interest to use for analysis
160-
/// * `max_pointers` - maximum number of candidate pointers to collect per pointer cluster
153+
/// Builds the initial analysis settings for base address detection.
161154
pub struct BaseAddressDetectionSettings {
162155
arch: Option<CoreArchitecture>,
156+
/// Analysis mode to use
163157
analysis: BaseAddressDetectionAnalysis,
158+
/// Minimum length of a string to be considered a point-of-interest
164159
min_string_len: u32,
160+
/// Byte boundary to align the base address to while brute-forcing
165161
alignment: NonZeroU32,
162+
/// Lower boundary of the base address range to test
166163
lower_boundary: u64,
164+
/// Upper boundary of the base address range to test
167165
upper_boundary: u64,
166+
/// Specifies types of points-of-interest to use for analysis
168167
poi_analysis: BaseAddressDetectionPOISetting,
168+
/// Maximum number of candidate pointers to collect per pointer cluster
169169
max_pointers: u32,
170170
}
171171

172172
impl BaseAddressDetectionSettings {
173173
pub(crate) fn into_raw(value: &Self) -> BNBaseAddressDetectionSettings {
174174
let arch_name = value
175175
.arch
176-
.map(|a| a.name().as_ptr())
177-
.unwrap_or(BASE_ADDRESS_AUTO_DETECTION_ARCH.as_ptr() as *const u8);
176+
.map(|a| a.name())
177+
.unwrap_or(BASE_ADDRESS_AUTO_DETECTION_ARCH.to_string());
178+
let c_arch_name = arch_name.to_cstr();
178179
BNBaseAddressDetectionSettings {
179-
Architecture: arch_name as *const c_char,
180+
Architecture: c_arch_name.into_raw(),
180181
Analysis: value.analysis.as_raw().as_ptr(),
181182
MinStrlen: value.min_string_len,
182183
Alignment: value.alignment.get(),
@@ -207,6 +208,9 @@ impl BaseAddressDetectionSettings {
207208
self
208209
}
209210

211+
/// Specify the lower boundary of the base address range to test.
212+
///
213+
/// NOTE: The passed `value` **must** be less than the upper boundary.
210214
pub fn low_boundary(mut self, value: u64) -> Self {
211215
assert!(
212216
self.upper_boundary >= value,
@@ -216,6 +220,9 @@ impl BaseAddressDetectionSettings {
216220
self
217221
}
218222

223+
/// Specify the upper boundary of the base address range to test.
224+
///
225+
/// NOTE: The passed `value` **must** be greater than the lower boundary.
219226
pub fn high_boundary(mut self, value: u64) -> Self {
220227
assert!(
221228
self.lower_boundary <= value,
@@ -230,6 +237,9 @@ impl BaseAddressDetectionSettings {
230237
self
231238
}
232239

240+
/// Specify the maximum number of candidate pointers to collect per pointer cluster.
241+
///
242+
/// NOTE: The passed `value` **must** be at least 2.
233243
pub fn max_pointers(mut self, value: u32) -> Self {
234244
assert!(value > 2, "max pointers must be at least 2");
235245
self.max_pointers = value;

rust/src/binary_view.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,7 +1392,7 @@ pub trait BinaryViewExt: BinaryViewBase {
13921392
for address in addresses {
13931393
let funcs = self.functions_at(address);
13941394
for func in funcs.into_iter() {
1395-
if func.start() == address && plat.map_or(true, |p| p == func.platform().as_ref()) {
1395+
if func.start() == address && plat.is_none_or(|p| p == func.platform().as_ref()) {
13961396
functions.push(func.clone());
13971397
}
13981398
}

0 commit comments

Comments
 (0)