Skip to content

Commit cb02af3

Browse files
committed
Fix clippy lints
1 parent 12fe44d commit cb02af3

23 files changed

+79
-98
lines changed

rust/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn main() {
55
let _ = std::fs::create_dir("target/doc");
66
let _ = std::fs::copy("../docs/img/favicon.ico", "target/doc/favicon.ico");
77
let _ = std::fs::copy(
8-
"under_construction.png",
8+
"assets/under_construction.png",
99
"target/doc/under_construction.png",
1010
);
1111
let _ = std::fs::copy("../docs/img/logo.png", "target/doc/logo.png");

rust/clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
too-many-arguments-threshold = 8

rust/src/architecture.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,25 +200,31 @@ impl From<BNInstructionInfo> for InstructionInfo {
200200
fn from(value: BNInstructionInfo) -> Self {
201201
// TODO: This is quite ugly, but we destructure the branch info so this will have to do.
202202
let mut branch_info = [None; NUM_BRANCH_INFO];
203-
for i in 0..value.branchCount.min(NUM_BRANCH_INFO) {
204-
let branch_target = value.branchTarget[i];
205-
branch_info[i] = Some(BranchInfo {
206-
kind: match value.branchType[i] {
207-
BNBranchType::UnconditionalBranch => BranchKind::Unconditional(branch_target),
208-
BNBranchType::FalseBranch => BranchKind::False(branch_target),
209-
BNBranchType::TrueBranch => BranchKind::True(branch_target),
210-
BNBranchType::CallDestination => BranchKind::Call(branch_target),
203+
for (i, slot) in branch_info
204+
.iter_mut()
205+
.enumerate()
206+
.take(value.branchCount.min(NUM_BRANCH_INFO))
207+
{
208+
let target = value.branchTarget[i];
209+
let kind = value.branchType[i];
210+
let arch = value.branchArch[i];
211+
*slot = Some(BranchInfo {
212+
kind: match kind {
213+
BNBranchType::UnconditionalBranch => BranchKind::Unconditional(target),
214+
BNBranchType::FalseBranch => BranchKind::False(target),
215+
BNBranchType::TrueBranch => BranchKind::True(target),
216+
BNBranchType::CallDestination => BranchKind::Call(target),
211217
BNBranchType::FunctionReturn => BranchKind::FunctionReturn,
212218
BNBranchType::SystemCall => BranchKind::SystemCall,
213219
BNBranchType::IndirectBranch => BranchKind::Indirect,
214220
BNBranchType::ExceptionBranch => BranchKind::Exception,
215221
BNBranchType::UnresolvedBranch => BranchKind::Unresolved,
216222
BNBranchType::UserDefinedBranch => BranchKind::UserDefined,
217223
},
218-
arch: if value.branchArch[i].is_null() {
224+
arch: if arch.is_null() {
219225
None
220226
} else {
221-
Some(unsafe { CoreArchitecture::from_raw(value.branchArch[i]) })
227+
Some(unsafe { CoreArchitecture::from_raw(arch) })
222228
},
223229
});
224230
}

rust/src/basicblock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl<C: BlockContext> BasicBlock<C> {
240240
// TODO iterated dominance frontier
241241
}
242242

243-
impl<'a, C: BlockContext> IntoIterator for &'a BasicBlock<C> {
243+
impl<C: BlockContext> IntoIterator for &BasicBlock<C> {
244244
type Item = C::Instruction;
245245
type IntoIter = C::Iter;
246246

rust/src/binaryview.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ pub trait BinaryViewExt: BinaryViewBase {
669669
let name_array = unsafe { Array::<QualifiedName>::new(result_names, result_count, ()) };
670670
id_array
671671
.into_iter()
672-
.zip(name_array.into_iter())
672+
.zip(&name_array)
673673
.map(|(id, name)| (id.to_owned(), name))
674674
.collect()
675675
}

rust/src/component.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ impl Component {
146146
}
147147

148148
/// Original name set for this component
149-
149+
///
150150
/// :note: The `.display_name` property should be used for `bv.get_component_by_path()` lookups.
151-
151+
///
152152
/// This can differ from the .display_name property if one of its sibling components has the same .original_name; In that
153153
/// case, .name will be an automatically generated unique name (e.g. "MyComponentName (1)") while .original_name will
154154
/// remain what was originally set (e.g. "MyComponentName")
155-
155+
///
156156
/// If this component has a duplicate name and is moved to a component where none of its siblings share its name,
157157
/// .name will return the original "MyComponentName"
158158
pub fn name(&self) -> BnString {

rust/src/databuffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl DataBuffer {
172172

173173
impl Default for DataBuffer {
174174
fn default() -> Self {
175-
Self(unsafe { BNCreateDataBuffer([].as_ptr() as *const c_void, 0) })
175+
Self(unsafe { BNCreateDataBuffer([].as_ptr(), 0) })
176176
}
177177
}
178178

rust/src/demangle.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,7 @@ impl Demangler {
304304
})
305305
}
306306

307-
extern "C" fn cb_free_var_name<C>(_ctxt: *mut c_void, name: *mut BNQualifiedName)
308-
where
309-
C: CustomDemangler,
310-
{
307+
extern "C" fn cb_free_var_name(_ctxt: *mut c_void, name: *mut BNQualifiedName) {
311308
ffi_wrap!("CustomDemangler::cb_free_var_name", unsafe {
312309
// TODO: What is the point of this free callback?
313310
// TODO: The core can just call BNFreeQualifiedName.
@@ -323,7 +320,7 @@ impl Demangler {
323320
context: ctxt as *mut c_void,
324321
isMangledString: Some(cb_is_mangled_string::<C>),
325322
demangle: Some(cb_demangle::<C>),
326-
freeVarName: Some(cb_free_var_name::<C>),
323+
freeVarName: Some(cb_free_var_name),
327324
};
328325

329326
unsafe {

rust/src/disassembly.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl From<InstructionTextToken> for BNInstructionTextToken {
285285
let kind_value = value.kind.try_value().unwrap_or(0);
286286
let operand = value.kind.try_operand().unwrap_or(0);
287287
let size = value.kind.try_size().unwrap_or(0);
288-
let type_names = value.kind.try_type_names().unwrap_or(vec![]);
288+
let type_names = value.kind.try_type_names().unwrap_or_default();
289289
Self {
290290
type_: value.kind.into(),
291291
// Expected to be freed with `InstructionTextToken::free_raw`.

rust/src/enterprise.rs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,39 @@ pub fn checkout_license(duration: Duration) -> Result<(), EnterpriseCheckoutErro
2020
return Ok(());
2121
}
2222

23-
if !is_server_initialized() {
24-
if !initialize_server() && is_server_floating_license() {
25-
return Err(EnterpriseCheckoutError(server_last_error().to_string()));
26-
}
23+
if !is_server_initialized() && !initialize_server() && is_server_floating_license() {
24+
return Err(EnterpriseCheckoutError(server_last_error().to_string()));
2725
}
2826

2927
if is_server_floating_license() {
3028
if !is_server_connected() && !connect_server() {
3129
return Err(EnterpriseCheckoutError(server_last_error().to_string()));
3230
}
3331

34-
if !is_server_authenticated() {
35-
if !authenticate_server_with_method("Keychain", false) {
36-
let Some(username) = std::env::var("BN_ENTERPRISE_USERNAME").ok() else {
37-
return Err(EnterpriseCheckoutError("BN_ENTERPRISE_USERNAME not set when attempting to authenticate with credentials".to_string()));
38-
};
39-
let Some(password) = std::env::var("BN_ENTERPRISE_PASSWORD").ok() else {
40-
return Err(EnterpriseCheckoutError("BN_ENTERPRISE_PASSWORD not set when attempting to authenticate with credentials".to_string()));
41-
};
42-
if !authenticate_server_with_credentials(username, password, true) {
43-
let failed_message = "Could not checkout a license: Not authenticated. Try one of the following: \n \
44-
- Log in and check out a license for an extended time\n \
45-
- Set BN_ENTERPRISE_USERNAME and BN_ENTERPRISE_PASSWORD environment variables\n \
46-
- Use binaryninja::enterprise::{authenticate_server_with_method OR authenticate_server_with_credentials} in your code";
47-
return Err(EnterpriseCheckoutError(failed_message.to_string()));
48-
}
32+
if !is_server_authenticated() && !authenticate_server_with_method("Keychain", false) {
33+
let Some(username) = std::env::var("BN_ENTERPRISE_USERNAME").ok() else {
34+
return Err(EnterpriseCheckoutError("BN_ENTERPRISE_USERNAME not set when attempting to authenticate with credentials".to_string()));
35+
};
36+
let Some(password) = std::env::var("BN_ENTERPRISE_PASSWORD").ok() else {
37+
return Err(EnterpriseCheckoutError("BN_ENTERPRISE_PASSWORD not set when attempting to authenticate with credentials".to_string()));
38+
};
39+
if !authenticate_server_with_credentials(username, password, true) {
40+
let failed_message = "Could not checkout a license: Not authenticated. Try one of the following: \n \
41+
- Log in and check out a license for an extended time\n \
42+
- Set BN_ENTERPRISE_USERNAME and BN_ENTERPRISE_PASSWORD environment variables\n \
43+
- Use binaryninja::enterprise::{authenticate_server_with_method OR authenticate_server_with_credentials} in your code";
44+
return Err(EnterpriseCheckoutError(failed_message.to_string()));
4945
}
5046
}
5147
}
5248

53-
if !is_server_license_still_activated()
54-
|| (!is_server_floating_license() && crate::license_expiration_time() < SystemTime::now())
49+
if (!is_server_license_still_activated()
50+
|| (!is_server_floating_license() && crate::license_expiration_time() < SystemTime::now()))
51+
&& !update_server_license(duration)
5552
{
56-
if !update_server_license(duration) {
57-
return Err(EnterpriseCheckoutError(
58-
"Failed to refresh expired license".to_string(),
59-
));
60-
}
53+
return Err(EnterpriseCheckoutError(
54+
"Failed to refresh expired license".to_string(),
55+
));
6156
}
6257

6358
Ok(())

0 commit comments

Comments
 (0)