Skip to content

Commit

Permalink
Address clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tmfink committed Jul 17, 2023
1 parent 8655a5a commit 0c4e7ff
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 18 deletions.
4 changes: 4 additions & 0 deletions capstone-rs/src/arch/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//! Contains architecture-specific types and modules

// We use explicit casts from c_int (and such) so the code compiles on platforms with different
// integer widths
#![allow(clippy::unnecessary_cast)]

use alloc::vec::Vec;
use core::fmt::Debug;
use core::marker::PhantomData;
Expand Down
12 changes: 2 additions & 10 deletions capstone-rs/src/capstone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,8 @@ impl Capstone {
// it *should* be safe to accept `&self` (instead of `&mut self`) in this method.

let mut ptr: *mut cs_insn = core::ptr::null_mut();
let insn_count = unsafe {
cs_disasm(
self.csh(),
code.as_ptr(),
code.len() as usize,
addr,
count as usize,
&mut ptr,
)
};
let insn_count =
unsafe { cs_disasm(self.csh(), code.as_ptr(), code.len(), addr, count, &mut ptr) };
if insn_count == 0 {
match self.error_result() {
Ok(_) => Ok(Instructions::new_empty()),
Expand Down
1 change: 1 addition & 0 deletions capstone-rs/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use libc::{self, c_char};
/// - This function "creates" a reference with an arbitrary lifetime, so be careful to limit the
/// lifetime appropriately
#[inline]
#[allow(clippy::unnecessary_cast)]
pub(crate) unsafe fn str_from_cstr_ptr<'a>(ptr: *const c_char) -> Option<&'a str> {
if ptr.is_null() {
return None;
Expand Down
2 changes: 1 addition & 1 deletion capstone-rs/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl<'a> Insn<'a> {
/// Instruction address
#[inline]
pub fn address(&self) -> u64 {
self.insn.address as u64
self.insn.address
}

/// Byte-level representation of the instruction
Expand Down
2 changes: 2 additions & 0 deletions capstone-rs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![doc = include_str!("../../README.md")]
#![cfg_attr(not(feature = "std"), no_std)]
// derive Default on enums was not stable until 1.62.0
#![allow(clippy::derivable_impls)]

// The `vec` macro cannot be imported directly since it conflicts with the `vec` module
#[allow(unused_imports)]
Expand Down
6 changes: 2 additions & 4 deletions capstone-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ fn build_capstone_cc() {

read_dir(dir)
.expect("Failed to read capstone source directory")
.into_iter()
.map(|e| e.expect("Failed to read capstone source directory"))
.filter(|e| filter(e))
.map(|e| {
Expand Down Expand Up @@ -357,9 +356,8 @@ fn main() {
// Otherwise, copy the pregenerated bindings
#[cfg(not(feature = "use_bindgen"))]
{
copy(&pregenerated_bindgen_header, &out_bindings_path)
.expect("Unable to update capstone bindings");
copy(&pregenerated_bindgen_impl, &out_impl_path)
copy(pregenerated_bindgen_header, out_bindings_path)
.expect("Unable to update capstone bindings");
copy(pregenerated_bindgen_impl, out_impl_path).expect("Unable to update capstone bindings");
}
}
6 changes: 3 additions & 3 deletions cstool/src/bin/cstool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn unhexed_bytes(input: Vec<u8>) -> Vec<u8> {
let mut curr_byte_str = String::with_capacity(2);
for b_u8 in input {
let b = char::from(b_u8);
if ('0'..='9').contains(&b) || ('a'..='f').contains(&b) || ('A'..='F').contains(&b) {
if b.is_ascii_hexdigit() {
curr_byte_str.push(b);
}

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

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

0 comments on commit 0c4e7ff

Please sign in to comment.