Skip to content

Commit 0c4e7ff

Browse files
committed
Address clippy warnings
1 parent 8655a5a commit 0c4e7ff

File tree

7 files changed

+15
-18
lines changed

7 files changed

+15
-18
lines changed

capstone-rs/src/arch/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
//! Contains architecture-specific types and modules
22
3+
// We use explicit casts from c_int (and such) so the code compiles on platforms with different
4+
// integer widths
5+
#![allow(clippy::unnecessary_cast)]
6+
37
use alloc::vec::Vec;
48
use core::fmt::Debug;
59
use core::marker::PhantomData;

capstone-rs/src/capstone.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,8 @@ impl Capstone {
202202
// it *should* be safe to accept `&self` (instead of `&mut self`) in this method.
203203

204204
let mut ptr: *mut cs_insn = core::ptr::null_mut();
205-
let insn_count = unsafe {
206-
cs_disasm(
207-
self.csh(),
208-
code.as_ptr(),
209-
code.len() as usize,
210-
addr,
211-
count as usize,
212-
&mut ptr,
213-
)
214-
};
205+
let insn_count =
206+
unsafe { cs_disasm(self.csh(), code.as_ptr(), code.len(), addr, count, &mut ptr) };
215207
if insn_count == 0 {
216208
match self.error_result() {
217209
Ok(_) => Ok(Instructions::new_empty()),

capstone-rs/src/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use libc::{self, c_char};
1212
/// - This function "creates" a reference with an arbitrary lifetime, so be careful to limit the
1313
/// lifetime appropriately
1414
#[inline]
15+
#[allow(clippy::unnecessary_cast)]
1516
pub(crate) unsafe fn str_from_cstr_ptr<'a>(ptr: *const c_char) -> Option<&'a str> {
1617
if ptr.is_null() {
1718
return None;

capstone-rs/src/instruction.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<'a> Insn<'a> {
263263
/// Instruction address
264264
#[inline]
265265
pub fn address(&self) -> u64 {
266-
self.insn.address as u64
266+
self.insn.address
267267
}
268268

269269
/// Byte-level representation of the instruction

capstone-rs/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![doc = include_str!("../../README.md")]
22
#![cfg_attr(not(feature = "std"), no_std)]
3+
// derive Default on enums was not stable until 1.62.0
4+
#![allow(clippy::derivable_impls)]
35

46
// The `vec` macro cannot be imported directly since it conflicts with the `vec` module
57
#[allow(unused_imports)]

capstone-sys/build.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ fn build_capstone_cc() {
7373

7474
read_dir(dir)
7575
.expect("Failed to read capstone source directory")
76-
.into_iter()
7776
.map(|e| e.expect("Failed to read capstone source directory"))
7877
.filter(|e| filter(e))
7978
.map(|e| {
@@ -357,9 +356,8 @@ fn main() {
357356
// Otherwise, copy the pregenerated bindings
358357
#[cfg(not(feature = "use_bindgen"))]
359358
{
360-
copy(&pregenerated_bindgen_header, &out_bindings_path)
361-
.expect("Unable to update capstone bindings");
362-
copy(&pregenerated_bindgen_impl, &out_impl_path)
359+
copy(pregenerated_bindgen_header, out_bindings_path)
363360
.expect("Unable to update capstone bindings");
361+
copy(pregenerated_bindgen_impl, out_impl_path).expect("Unable to update capstone bindings");
364362
}
365363
}

cstool/src/bin/cstool.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn unhexed_bytes(input: Vec<u8>) -> Vec<u8> {
5050
let mut curr_byte_str = String::with_capacity(2);
5151
for b_u8 in input {
5252
let b = char::from(b_u8);
53-
if ('0'..='9').contains(&b) || ('a'..='f').contains(&b) || ('A'..='F').contains(&b) {
53+
if b.is_ascii_hexdigit() {
5454
curr_byte_str.push(b);
5555
}
5656

@@ -112,7 +112,7 @@ fn disasm<T: Iterator<Item = ExtraMode>>(
112112
("insn groups:", group_names(&cs, detail.groups())),
113113
];
114114

115-
for &(ref name, ref message) in output.iter() {
115+
for (name, message) in output.iter() {
116116
let _ = writeln!(&mut handle, "{:13}{:12} {}", "", name, message).is_ok();
117117
}
118118
}
@@ -270,7 +270,7 @@ fn main() {
270270
Err(_) => DEFAULT_CAPACITY,
271271
Ok(metadata) => metadata.len() as usize,
272272
};
273-
let mut buf = Vec::with_capacity(capacity as usize);
273+
let mut buf = Vec::with_capacity(capacity);
274274
file.read_to_end(&mut buf).expect_exit();
275275
buf
276276
} else if let Some(code) = matches.value_of(CODE_ARG) {

0 commit comments

Comments
 (0)