Fix lint errors (#1909)

* fix lints.

* more lint fix.

* even more lint fixes.

* always more lint fixes.

* lint fix.

* allow unused qualifications for crate when it could be confusing.

* Still lint fixes.

* Lint fixes on generated code.

* Some lint fixes.
This commit is contained in:
Romain Malmain 2024-03-05 14:16:26 +01:00 committed by GitHub
parent b7efe8eb7d
commit d96a1426d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
33 changed files with 56 additions and 55 deletions

View File

@ -251,7 +251,7 @@ where
/// ``CachedOnDiskCorpus`` Python bindings
#[cfg(feature = "python")]
#[allow(clippy::unnecessary_fallible_conversions)]
#[allow(clippy::unnecessary_fallible_conversions, unused_qualifications)]
pub mod pybind {
use alloc::string::String;
use std::path::PathBuf;

View File

@ -429,7 +429,7 @@ where
/// `InMemoryCorpus` Python bindings
#[cfg(feature = "python")]
#[allow(clippy::unnecessary_fallible_conversions)]
#[allow(clippy::unnecessary_fallible_conversions, unused_qualifications)]
pub mod pybind {
use pyo3::prelude::*;
use serde::{Deserialize, Serialize};

View File

@ -439,7 +439,7 @@ where
}
#[cfg(feature = "python")]
#[allow(clippy::unnecessary_fallible_conversions)]
#[allow(clippy::unnecessary_fallible_conversions, unused_qualifications)]
/// `InMemoryOnDiskCorpus` Python bindings
pub mod pybind {
use alloc::string::String;

View File

@ -262,7 +262,7 @@ where
}
#[cfg(feature = "python")]
#[allow(clippy::unnecessary_fallible_conversions)]
#[allow(clippy::unnecessary_fallible_conversions, unused_qualifications)]
/// `OnDiskCorpus` Python bindings
pub mod pybind {
use alloc::string::String;

View File

@ -206,7 +206,7 @@ where
self.shmem_provider.post_fork(true)?;
#[cfg(feature = "std")]
std::thread::sleep(std::time::Duration::from_millis(index * 10));
std::thread::sleep(Duration::from_millis(index * 10));
#[cfg(feature = "std")]
if !debug_output {
@ -549,7 +549,7 @@ where
}
}
std::thread::sleep(std::time::Duration::from_millis(10));
std::thread::sleep(Duration::from_millis(10));
// Spawn clients
let mut index = 0_u64;
@ -568,7 +568,7 @@ where
log::info!("{:?} PostFork", unsafe { libc::getpid() });
self.shmem_provider.post_fork(true)?;
std::thread::sleep(std::time::Duration::from_millis(index * 10));
std::thread::sleep(Duration::from_millis(index * 10));
if !debug_output {
if let Some(file) = &self.opened_stdout_file {

View File

@ -598,7 +598,7 @@ where
/// `SimpleEventManager` Python bindings
#[cfg(feature = "python")]
#[allow(missing_docs)]
#[allow(clippy::unnecessary_fallible_conversions)]
#[allow(clippy::unnecessary_fallible_conversions, unused_qualifications)]
pub mod pybind {
use pyo3::prelude::*;

View File

@ -55,7 +55,7 @@ use crate::{
/// Tries to create (synchronously) a [`TcpListener`] that is `nonblocking` (for later use in tokio).
/// Will error if the port is already in use (or other errors occur)
fn create_nonblocking_listener<A: ToSocketAddrs>(addr: A) -> Result<TcpListener, Error> {
let listener = std::net::TcpListener::bind(addr)?;
let listener = TcpListener::bind(addr)?;
listener.set_nonblocking(true)?;
Ok(listener)
}
@ -1065,8 +1065,7 @@ where
/// Launch the restarting manager
pub fn launch(&mut self) -> Result<(Option<S>, TcpRestartingEventManager<S, SP>), Error> {
// We start ourself as child process to actually fuzz
let (staterestorer, _new_shmem_provider, core_id) = if std::env::var(_ENV_FUZZER_SENDER)
.is_err()
let (staterestorer, _new_shmem_provider, core_id) = if env::var(_ENV_FUZZER_SENDER).is_err()
{
let broker_things = |mut broker: TcpEventBroker<S::Input, MT>, _remote_broker_addr| {
if let Some(exit_cleanly_after) = self.exit_cleanly_after {

View File

@ -37,8 +37,8 @@ impl<A, B, OTA, OTB, DOT> DiffExecutor<A, B, OTA, OTB, DOT> {
primary,
secondary,
observers: UnsafeCell::new(ProxyObserversTuple {
primary: OwnedMutPtr::Ptr(core::ptr::null_mut()),
secondary: OwnedMutPtr::Ptr(core::ptr::null_mut()),
primary: OwnedMutPtr::Ptr(ptr::null_mut()),
secondary: OwnedMutPtr::Ptr(ptr::null_mut()),
differential: observers,
}),
}

View File

@ -661,7 +661,7 @@ mod tests {
#[cfg(feature = "python")]
#[allow(missing_docs)]
#[allow(clippy::unnecessary_fallible_conversions)]
#[allow(clippy::unnecessary_fallible_conversions, unused_qualifications)]
/// `InProcess` Python bindings
pub mod pybind {
use alloc::boxed::Box;

View File

@ -1096,7 +1096,7 @@ impl From<bool> for ConstFeedback {
/// `Feedback` Python bindings
#[cfg(feature = "python")]
#[allow(clippy::unnecessary_fallible_conversions)]
#[allow(clippy::unnecessary_fallible_conversions, unused_qualifications)]
#[allow(missing_docs)]
pub mod pybind {
use core::ptr;

View File

@ -170,7 +170,7 @@ where
/// `Generator` Python bindings
#[allow(missing_docs)]
#[cfg(feature = "python")]
#[allow(clippy::unnecessary_fallible_conversions)]
#[allow(clippy::unnecessary_fallible_conversions, unused_qualifications)]
pub mod pybind {
use alloc::vec::Vec;

View File

@ -1211,9 +1211,9 @@ impl ClientPerfMonitor {
}
#[cfg(feature = "introspection")]
impl core::fmt::Display for ClientPerfMonitor {
impl fmt::Display for ClientPerfMonitor {
#[allow(clippy::cast_precision_loss)]
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
// Calculate the elapsed time from the monitor
let elapsed: f64 = self.elapsed_cycles() as f64;
@ -1291,7 +1291,7 @@ impl Default for ClientPerfMonitor {
}
/// `Monitor` Python bindings
#[cfg(feature = "python")]
#[allow(clippy::unnecessary_fallible_conversions)]
#[allow(clippy::unnecessary_fallible_conversions, unused_qualifications)]
#[allow(missing_docs)]
pub mod pybind {
use alloc::{boxed::Box, vec::Vec};

View File

@ -518,7 +518,7 @@ impl TuiMonitor {
.map_or("None".to_string(), ToString::to_string);
let stability = client.get_user_stats("stability").map_or(
UserStats::new(UserStatsValue::Ratio(0, 100), AggregatorOps::Avg),
core::clone::Clone::clone,
Clone::clone,
);
if afl_stats != "None" {
@ -616,7 +616,7 @@ fn run_tui_thread<W: Write + Send + Sync + 'static>(
let timeout = tick_rate
.checked_sub(last_tick.elapsed())
.unwrap_or_else(|| Duration::from_secs(0));
if crossterm::event::poll(timeout)? {
if event::poll(timeout)? {
if let Event::Key(key) = event::read()? {
match key.code {
KeyCode::Char(c) => ui.on_key(c),

View File

@ -601,7 +601,7 @@ mod tests {
/// `SchedulerMutator` Python bindings
#[cfg(feature = "python")]
#[allow(missing_docs)]
#[allow(clippy::unnecessary_fallible_conversions)]
#[allow(clippy::unnecessary_fallible_conversions, unused_qualifications)]
pub mod pybind {
use pyo3::prelude::*;

View File

@ -28,13 +28,13 @@ pub struct Location(usize);
impl Debug for Location {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
core::fmt::Debug::fmt(&self.0, f)
Debug::fmt(&self.0, f)
}
}
impl Display for Location {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
core::fmt::Display::fmt(&self.0, f)
Display::fmt(&self.0, f)
}
}

View File

@ -93,7 +93,7 @@ impl<R: Read> MessageFileReader<R> {
Some(Ok((message_id, message)))
}
Err(e) => match *e {
bincode::ErrorKind::Io(ref io_err) => match io_err.kind() {
ErrorKind::Io(ref io_err) => match io_err.kind() {
io::ErrorKind::UnexpectedEof => None,
_ => Some(Err(e)),
},

View File

@ -378,7 +378,7 @@ where
#[cfg(feature = "python")]
#[allow(missing_docs)]
#[allow(clippy::unnecessary_fallible_conversions)]
#[allow(clippy::unnecessary_fallible_conversions, unused_qualifications)]
/// `StdMutationalStage` Python bindings
pub mod pybind {
use pyo3::prelude::*;

View File

@ -984,6 +984,7 @@ impl log::Log for SimpleFdLogger {
/// # Safety
/// The function is arguably safe, but it might have undesirable side effects since it closes `stdout` and `stderr`.
#[cfg(all(unix, feature = "std"))]
#[allow(unused_qualifications)]
pub unsafe fn dup_and_mute_outputs() -> Result<(RawFd, RawFd), Error> {
let old_stdout = stdout().as_raw_fd();
let old_stderr = stderr().as_raw_fd();
@ -1010,7 +1011,7 @@ pub unsafe fn set_error_print_panic_hook(new_stderr: RawFd) {
let mut f = unsafe { File::from_raw_fd(new_stderr) };
writeln!(f, "{panic_info}",)
.unwrap_or_else(|err| println!("Failed to log to fd {new_stderr}: {err}"));
std::mem::forget(f);
mem::forget(f);
}));
}

View File

@ -3210,7 +3210,7 @@ where
Ok(stream) => stream,
Err(e) => {
match e.kind() {
std::io::ErrorKind::ConnectionRefused => {
ErrorKind::ConnectionRefused => {
//connection refused. loop till the broker is up
loop {
match TcpStream::connect((_LLMP_CONNECT_ADDR, port)) {

View File

@ -435,7 +435,7 @@ mod tests {
}
#[cfg(feature = "python")]
#[allow(clippy::unnecessary_fallible_conversions)]
#[allow(clippy::unnecessary_fallible_conversions, unused_qualifications)]
#[allow(missing_docs)]
/// `Rand` Python bindings
pub mod pybind {

View File

@ -162,7 +162,7 @@ impl ToolWrapper for ArWrapper {
.base_args
.iter()
.map(|r| {
let arg_as_path = std::path::PathBuf::from(r);
let arg_as_path = PathBuf::from(r);
if r.ends_with('.') {
r.to_string()
} else {
@ -185,7 +185,7 @@ impl ToolWrapper for ArWrapper {
})
.collect::<Vec<_>>();
let Ok(ar_path) = std::env::var("LLVM_AR_PATH") else {
let Ok(ar_path) = env::var("LLVM_AR_PATH") else {
panic!("Couldn't find llvm-ar. Specify the `LLVM_AR_PATH` environment variable");
};

View File

@ -152,7 +152,7 @@ impl ToolWrapper for ClangWrapper {
let mut suppress_linking = 0;
let mut i = 1;
while i < args.len() {
let arg_as_path = std::path::Path::new(args[i].as_ref());
let arg_as_path = Path::new(args[i].as_ref());
if arg_as_path
.extension()
@ -329,7 +329,7 @@ impl ToolWrapper for ClangWrapper {
.base_args
.iter()
.map(|r| {
let arg_as_path = std::path::PathBuf::from(r);
let arg_as_path = PathBuf::from(r);
if r.ends_with('.') {
r.to_string()
} else {
@ -366,7 +366,7 @@ impl ToolWrapper for ClangWrapper {
// No output specified, we need to rewrite the single .c file's name into a -o
// argument.
for arg in &base_args {
let arg_as_path = std::path::PathBuf::from(arg);
let arg_as_path = PathBuf::from(arg);
if !arg.ends_with('.') && !arg.starts_with('-') {
if let Some(extension) = arg_as_path.extension() {
let extension = extension.to_str().unwrap();
@ -376,7 +376,7 @@ impl ToolWrapper for ClangWrapper {
args.push("-o".to_string());
args.push(if self.linking {
configuration
.replace_extension(&std::path::PathBuf::from("a.out"))
.replace_extension(&PathBuf::from("a.out"))
.into_os_string()
.into_string()
.unwrap()

View File

@ -146,12 +146,12 @@ impl Configuration {
let output = output.to_str().unwrap();
let new_filename = if let Some((filename, extension)) = output.split_once('.') {
if let crate::Configuration::Default = self {
if let Configuration::Default = self {
format!("{filename}.{extension}")
} else {
format!("{filename}.{self}.{extension}")
}
} else if let crate::Configuration::Default = self {
} else if let Configuration::Default = self {
output.to_string()
} else {
format!("{output}.{self}")

View File

@ -170,7 +170,7 @@ impl ToolWrapper for LibtoolWrapper {
.base_args
.iter()
.map(|r| {
let arg_as_path = std::path::PathBuf::from(r);
let arg_as_path = PathBuf::from(r);
if r.ends_with('.') {
r.to_string()
} else {
@ -191,7 +191,7 @@ impl ToolWrapper for LibtoolWrapper {
})
.collect::<Vec<_>>();
let libtool_path = if let Ok(libtool_dir) = std::env::var("LIBTOOL_DIR") {
let libtool_path = if let Ok(libtool_dir) = env::var("LIBTOOL_DIR") {
format!("{libtool_dir}/libtool")
} else {
"./libtool".to_string()

View File

@ -542,7 +542,7 @@ impl AsanRuntime {
#[allow(clippy::items_after_statements)]
#[allow(clippy::too_many_lines)]
fn hook_functions(&mut self, gum: &Gum) {
let mut interceptor = frida_gum::interceptor::Interceptor::obtain(gum);
let mut interceptor = Interceptor::obtain(gum);
macro_rules! hook_func {
($lib:expr, $name:ident, ($($param:ident : $param_type:ty),*), $return_type:ty) => {

View File

@ -661,11 +661,11 @@ impl CmpLogRuntime {
)> {
let bytes = instr.bytes();
let mut decoder =
iced_x86::Decoder::with_ip(64, bytes, instr.address(), iced_x86::DecoderOptions::NONE);
iced_x86::Decoder::with_ip(64, bytes, instr.address(), DecoderOptions::NONE);
if !decoder.can_decode() {
return None;
}
let mut instruction = iced_x86::Instruction::default();
let mut instruction = Instruction::default();
decoder.decode_out(&mut instruction);
match instruction.mnemonic() {
iced_x86::Mnemonic::Cmp | iced_x86::Mnemonic::Sub => {} // continue

View File

@ -10,7 +10,7 @@ fn main() {
let build = bindgen::builder()
.header("src/harness_wrap.h")
.generate_comments(true)
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.expect("Couldn't generate the harness wrapper!");

View File

@ -105,6 +105,7 @@ mod harness_wrap {
#![allow(improper_ctypes)]
#![allow(clippy::unreadable_literal)]
#![allow(missing_docs)]
#![allow(unused_qualifications)]
include!(concat!(env!("OUT_DIR"), "/harness_wrap.rs"));
}

View File

@ -131,7 +131,7 @@ impl LibfuzzerOptions {
let name = if let Some(executable) = std::env::current_exe().ok().and_then(|path| {
path.file_name()
.and_then(std::ffi::OsStr::to_str)
.map(std::string::ToString::to_string)
.map(ToString::to_string)
}) {
executable
} else {
@ -397,7 +397,7 @@ impl<'a> LibfuzzerOptionsBuilder<'a> {
unknown: self
.unknown
.into_iter()
.map(std::string::ToString::to_string)
.map(ToString::to_string)
.collect(),
}
}

View File

@ -135,7 +135,7 @@ pub fn generate(
.allowlist_function("device_list_all")
.allowlist_function("libafl_.*")
.blocklist_function("main_loop_wait") // bindgen issue #1313
.parse_callbacks(Box::new(bindgen::CargoCallbacks));
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()));
// arch specific functions
let bindings = if cpu_target == "i386" || cpu_target == "x86_64" {

View File

@ -214,7 +214,7 @@ fn main() {
.header("src/sanitizer_interfaces.h")
.use_core()
.generate_comments(true)
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.expect("Couldn't generate the sanitizer headers!");

View File

@ -29,13 +29,12 @@ pub const CMPLOG_MAP_SIZE: usize = CMPLOG_MAP_W * CMPLOG_MAP_H;
pub const CMPLOG_RTN_LEN: usize = 32;
/// The hight of a cmplog routine map
pub const CMPLOG_MAP_RTN_H: usize = (CMPLOG_MAP_H * core::mem::size_of::<CmpLogInstruction>())
/ core::mem::size_of::<CmpLogRoutine>();
pub const CMPLOG_MAP_RTN_H: usize =
(CMPLOG_MAP_H * mem::size_of::<CmpLogInstruction>()) / mem::size_of::<CmpLogRoutine>();
/// The height of extended rountine map
pub const CMPLOG_MAP_RTN_EXTENDED_H: usize = CMPLOG_MAP_H
* core::mem::size_of::<AFLppCmpLogOperands>()
/ core::mem::size_of::<AFLppCmpLogFnOperands>();
pub const CMPLOG_MAP_RTN_EXTENDED_H: usize =
CMPLOG_MAP_H * mem::size_of::<AFLppCmpLogOperands>() / mem::size_of::<AFLppCmpLogFnOperands>();
/// `CmpLog` instruction kind
pub const CMPLOG_KIND_INS: u8 = 0;
@ -277,7 +276,7 @@ pub union AFLppCmpLogVals {
}
impl Debug for AFLppCmpLogVals {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("AFLppCmpLogVals").finish_non_exhaustive()
}
}
@ -324,7 +323,7 @@ pub struct CmpLogMap {
impl Default for CmpLogMap {
fn default() -> Self {
unsafe { core::mem::zeroed() }
unsafe { mem::zeroed() }
}
}
@ -493,7 +492,7 @@ impl<'de> Deserialize<'de> for AFLppCmpLogMap {
D: Deserializer<'de>,
{
let bytes = Vec::<u8>::deserialize(deserializer)?;
let map: Self = unsafe { core::ptr::read(bytes.as_ptr() as *const _) };
let map: Self = unsafe { ptr::read(bytes.as_ptr() as *const _) };
Ok(map)
}
}

View File

@ -98,6 +98,7 @@ pub mod sanitizer_ifaces {
#![allow(clippy::unreadable_literal)]
#![allow(missing_docs)]
#![allow(missing_debug_implementations)]
#![allow(unused_qualifications)]
include!(concat!(env!("OUT_DIR"), "/sanitizer_interfaces.rs"));
}