Skip to content

Commit

Permalink
chore: fix new clippy warnings in 1.72
Browse files Browse the repository at this point in the history
  • Loading branch information
vthib committed Aug 27, 2023
1 parent e18c5f0 commit 788a2cc
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 21 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"boreal-parser",
"boreal",
Expand Down
4 changes: 2 additions & 2 deletions boreal-cli/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,15 +579,15 @@ rule a {
.assert()
.stdout(
predicate::str::is_match(
r#"Evaluation \{
r"Evaluation \{
no_scan_eval_duration: .*,
ac_duration: .*,
ac_confirm_duration: .*,
nb_ac_matches: .*,
rules_eval_duration: .*,
raw_regexes_eval_duration: .*,
\}
"#,
",
)
.unwrap(),
)
Expand Down
2 changes: 1 addition & 1 deletion boreal-parser/src/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ mod tests {
);
parse(
regex,
r#"/a\/b\cd/isb"#,
r"/a\/b\cd/isb",
"b",
Regex {
ast: Node::Concat(vec![
Expand Down
10 changes: 7 additions & 3 deletions boreal/src/evaluator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ impl Evaluator<'_, '_, '_, '_, '_> {
}

match expr {
Expression::Filesize => Ok(Value::Integer(self.mem.len() as i64)),
Expression::Filesize => Ok(Value::Integer(
self.mem.len().try_into().unwrap_or(i64::MAX),
)),

#[cfg(feature = "object")]
Expression::Entrypoint => {
Expand Down Expand Up @@ -372,7 +374,8 @@ impl Evaluator<'_, '_, '_, '_, '_> {
Ok(v) if v != 0 => {
let var = get_var!(self, *variable_index);
var.find_match_occurence(self.scan_data, v - 1)
.map(|mat| Value::Integer(mat.start as i64))
.and_then(|mat| i64::try_from(mat.start).ok())
.map(Value::Integer)
.ok_or(PoisonKind::Undefined)
}
Ok(_) | Err(_) => Err(PoisonKind::Undefined),
Expand All @@ -388,7 +391,8 @@ impl Evaluator<'_, '_, '_, '_, '_> {
Ok(v) if v != 0 => {
let var = get_var!(self, *variable_index);
var.find_match_occurence(self.scan_data, v - 1)
.map(|mat| Value::Integer(mat.len() as i64))
.and_then(|mat| i64::try_from(mat.len()).ok())
.map(Value::Integer)
.ok_or(PoisonKind::Undefined)
}
Ok(_) | Err(_) => Err(PoisonKind::Undefined),
Expand Down
2 changes: 1 addition & 1 deletion boreal/src/module/macho.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ impl MachO {
continue;
}
}
return Some(Value::Integer(i as i64));
return Some(i.into());
}
None
}
Expand Down
8 changes: 3 additions & 5 deletions boreal/src/module/pe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl Module for Pe {
}

fn get_static_values(&self) -> HashMap<&'static str, StaticValue> {
#[allow(clippy::cast_possible_wrap)]
[
(
"MACHINE_UNKNOWN",
Expand Down Expand Up @@ -1303,10 +1304,7 @@ impl Pe {
if let Some((signatures, is_signed)) =
signatures::get_signatures(&data_dirs, mem, token)
{
let _r = map.insert(
"number_of_signatures",
Value::Integer(signatures.len() as _),
);
let _r = map.insert("number_of_signatures", signatures.len().into());
let _r = map.insert("is_signed", Value::Integer(is_signed.into()));
let _r = map.insert("signatures", Value::Array(signatures));
} else {
Expand Down Expand Up @@ -1864,7 +1862,7 @@ pub fn add_version_infos(mem: &[u8], offset: u32, out: &mut HashMap<&'static str
};

out.extend([
("number_of_version_infos", (infos.len() as i64).into()),
("number_of_version_infos", infos.len().into()),
(
"version_info",
Value::Dictionary(
Expand Down
2 changes: 1 addition & 1 deletion boreal/src/scanner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl Inner {
let mut var_evals_iterator = self
.variables
.iter()
.zip(ac_matches.into_iter())
.zip(ac_matches)
.map(|(var, ac_result)| VariableEvaluation::new(var, eval_params, ac_result));

for (rule, is_global) in self
Expand Down
4 changes: 2 additions & 2 deletions boreal/tests/it/full.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ rule b {
);

compiler.add_rules_in_namespace(
r#"
r"
rule c {
strings:
$rgx = /\s_\w+\d{,2}/
Expand All @@ -47,7 +47,7 @@ rule c {
condition:
any of them
}
"#,
",
"2nd namespace",
);

Expand Down
2 changes: 1 addition & 1 deletion boreal/tests/it/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ rule a {
);

// escaped unicode char is accepted.
let checker = Checker::new(r#"rule a { strings: $a = /\µ/ condition: $a }"#);
let checker = Checker::new(r"rule a { strings: $a = /\µ/ condition: $a }");
checker.check("µ".as_bytes(), true);
}

Expand Down
10 changes: 5 additions & 5 deletions boreal/tests/it/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn test_variable_err() {
fn test_variable_regex_modifiers() {
// \x76 is 'v'
let checker = Checker::new(
r#"
r"
rule a {
strings:
$a = /f[aF]T[d-g]\x76/ nocase
Expand All @@ -62,7 +62,7 @@ rule a {
$d = /.{,2}quu/ nocase fullword
condition:
any of them
}"#,
}",
);

// Nocase: work on literals, ranges, and explicit hexa char
Expand Down Expand Up @@ -215,7 +215,7 @@ fn test_variable_regex_wide() {
checker.check(b"<\x00a\x009\x00d\x00>\x00", false);
checker.check(b"a\x009\x00", false);

let checker = build_checker(r#"\d[^abc]d$"#, "wide");
let checker = build_checker(r"\d[^abc]d$", "wide");
checker.check(b"13d", false);
checker.check(b"1\x003\x00d\x00", true);
checker.check(b"1\x003\x00d", false);
Expand Down Expand Up @@ -592,13 +592,13 @@ rule a {{
fn test_variable_boundary_ac_confirm() {
// Make sure the boundary is taken into account when confirming an ac match.
let checker = Checker::new(
r#"
r"
rule a {
strings:
$a = /\Wabcd\W/
condition:
$a
}"#,
}",
);

checker.check(b"aabcde", false);
Expand Down

0 comments on commit 788a2cc

Please sign in to comment.