fix clippy lints

This commit is contained in:
Christian Poveda 2022-10-18 12:05:27 -05:00
parent 66388deae3
commit c1d1f1b694
No known key found for this signature in database
GPG Key ID: 3B422F347D81A9E8
4 changed files with 38 additions and 52 deletions

View File

@ -8,8 +8,7 @@ use std::fs;
use std::io::Write;
use std::path::Path;
const LIBCLANG_VERSION_DIRS: &'static [&'static str] =
&["libclang-5", "libclang-9"];
const LIBCLANG_VERSION_DIRS: &[&str] = &["libclang-5", "libclang-9"];
fn main() {
println!("cargo:rerun-if-changed=build.rs");
@ -26,7 +25,7 @@ fn main() {
for entry in fs::read_dir(dir).unwrap() {
let entry = entry.unwrap();
let path = entry.path();
let path = path.canonicalize().unwrap_or_else(|_| path.into());
let path = path.canonicalize().unwrap_or(path);
if path.extension().map(|e| e.to_string_lossy()) !=
Some("rs".into())
{

View File

@ -327,12 +327,7 @@ impl Arbitrary for ArrayDimensionC {
let dimensions = g.gen_range(0, 5);
let mut def = String::new();
let lower_bound;
if cfg!(feature = "zero-sized-arrays") {
lower_bound = 0;
} else {
lower_bound = 1;
}
let lower_bound = i32::from(cfg!(feature = "zero-sized-arrays"));
for _ in 1..dimensions {
// 16 is an arbitrary "not too big" number for capping array size.
@ -400,7 +395,7 @@ impl Arbitrary for StructDeclarationC {
fn arbitrary<G: Gen>(g: &mut G) -> StructDeclarationC {
// Reduce generator size as a method of putting a bound on recursion.
// When size < 1 the empty list is generated.
let reduced_size: usize = (g.size() / 2) as usize + 1;
let reduced_size: usize = (g.size() / 2) + 1;
let mut decl_list: DeclarationListC =
Arbitrary::arbitrary(&mut StdGen::new(thread_rng(), reduced_size));
let mut fields: DeclarationListC = DeclarationListC { decls: vec![] };
@ -448,7 +443,7 @@ impl Arbitrary for UnionDeclarationC {
fn arbitrary<G: Gen>(g: &mut G) -> UnionDeclarationC {
// Reduce generator size as a method of putting a bound on recursion.
// When size < 1 the empty list is generated.
let reduced_size: usize = (g.size() / 2) as usize + 1;
let reduced_size: usize = (g.size() / 2) + 1;
let mut decl_list: DeclarationListC =
Arbitrary::arbitrary(&mut StdGen::new(thread_rng(), reduced_size));
let mut fields: DeclarationListC = DeclarationListC { decls: vec![] };

View File

@ -63,32 +63,27 @@ fn run_predicate_script(
header_file.write_all(header.to_string().as_bytes())?;
header_file.sync_all()?;
let header_path_string;
match header_path.into_os_string().into_string() {
Ok(s) => header_path_string = s,
Err(_) => return Err(From::from("error converting path into String")),
}
let header_path_string = header_path
.into_os_string()
.into_string()
.map_err(|_| "error converting path into String")?;
let mut predicate_script_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
predicate_script_path.push("../../csmith-fuzzing/predicate.py");
let predicate_script_path_string;
match predicate_script_path.into_os_string().into_string() {
Ok(s) => predicate_script_path_string = s,
Err(_) => return Err(From::from("error converting path into String")),
}
let predicate_script_path_string = predicate_script_path
.into_os_string()
.into_string()
.map_err(|_| "error converting path into String")?;
// Copy generated temp files to output_path directory for inspection.
// If `None`, output path not specified, don't copy.
match CONTEXT.lock().unwrap().output_path {
Some(ref path) => {
Command::new("cp")
.arg("-a")
.arg(&dir.path().to_str().unwrap())
.arg(&path)
.output()?;
}
None => {}
if let Some(ref path) = CONTEXT.lock().unwrap().output_path {
Command::new("cp")
.arg("-a")
.arg(dir.path().to_str().unwrap())
.arg(path)
.output()?;
}
Ok(Command::new(&predicate_script_path_string)
@ -101,10 +96,10 @@ fn run_predicate_script(
// status of that command.
fn bindgen_prop(header: fuzzers::HeaderC) -> TestResult {
match run_predicate_script(header) {
Ok(o) => return TestResult::from_bool(o.status.success()),
Ok(o) => TestResult::from_bool(o.status.success()),
Err(e) => {
println!("{:?}", e);
return TestResult::from_bool(false);
TestResult::from_bool(false)
}
}
}
@ -118,12 +113,9 @@ pub fn test_bindgen(
tests: usize,
output_path: Option<&str>,
) {
match output_path {
Some(path) => {
CONTEXT.lock().unwrap().output_path =
Some(String::from(PathBuf::from(path).to_str().unwrap()));
}
None => {} // Path not specified, don't provide output.
if let Some(path) = output_path {
CONTEXT.lock().unwrap().output_path =
Some(String::from(PathBuf::from(path).to_str().unwrap()));
}
QuickCheck::new()

View File

@ -13,84 +13,84 @@ use rand::thread_rng;
#[test]
fn test_declaraion_c_does_not_panic() {
let ref mut gen = StdGen::new(thread_rng(), 50);
let gen = &mut StdGen::new(thread_rng(), 50);
let _: DeclarationC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_declaraion_list_c_does_not_panic() {
let ref mut gen = StdGen::new(thread_rng(), 50);
let gen = &mut StdGen::new(thread_rng(), 50);
let _: DeclarationListC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_base_type_c_does_not_panic() {
let ref mut gen = StdGen::new(thread_rng(), 50);
let gen = &mut StdGen::new(thread_rng(), 50);
let _: BaseTypeC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_type_qualifier_c_does_not_panic() {
let ref mut gen = StdGen::new(thread_rng(), 50);
let gen = &mut StdGen::new(thread_rng(), 50);
let _: TypeQualifierC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_pointer_level_c_does_not_panic() {
let ref mut gen = StdGen::new(thread_rng(), 50);
let gen = &mut StdGen::new(thread_rng(), 50);
let _: PointerLevelC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_array_dimension_c_does_not_panic() {
let ref mut gen = StdGen::new(thread_rng(), 50);
let gen = &mut StdGen::new(thread_rng(), 50);
let _: ArrayDimensionC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_basic_type_declaration_c_does_not_panic() {
let ref mut gen = StdGen::new(thread_rng(), 50);
let gen = &mut StdGen::new(thread_rng(), 50);
let _: BasicTypeDeclarationC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_struct_declaration_c_does_not_panic() {
let ref mut gen = StdGen::new(thread_rng(), 50);
let gen = &mut StdGen::new(thread_rng(), 50);
let _: StructDeclarationC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_union_declaration_c_does_not_panic() {
let ref mut gen = StdGen::new(thread_rng(), 50);
let gen = &mut StdGen::new(thread_rng(), 50);
let _: UnionDeclarationC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_function_pointer_declaration_c_does_not_panic() {
let ref mut gen = StdGen::new(thread_rng(), 50);
let gen = &mut StdGen::new(thread_rng(), 50);
let _: FunctionPointerDeclarationC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_function_prototype_c_does_not_panic() {
let ref mut gen = StdGen::new(thread_rng(), 50);
let gen = &mut StdGen::new(thread_rng(), 50);
let _: FunctionPrototypeC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_parameter_c_does_not_panic() {
let ref mut gen = StdGen::new(thread_rng(), 50);
let gen = &mut StdGen::new(thread_rng(), 50);
let _: ParameterC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_parameter_list_c_does_not_panic() {
let ref mut gen = StdGen::new(thread_rng(), 50);
let gen = &mut StdGen::new(thread_rng(), 50);
let _: ParameterListC = Arbitrary::arbitrary(gen);
}
#[test]
fn test_header_c_does_not_panic() {
let ref mut gen = StdGen::new(thread_rng(), 50);
let gen = &mut StdGen::new(thread_rng(), 50);
let _: HeaderC = Arbitrary::arbitrary(gen);
}