1
0
Fork 0
mirror of https://github.com/BLAKE3-team/BLAKE3 synced 2024-05-08 19:06:02 +02:00

do a saturating_add for files_failed

This commit is contained in:
Jack O'Connor 2023-02-04 09:59:01 -08:00
parent 98135307bf
commit f1dcbeadc2

View File

@ -551,7 +551,9 @@ fn check_one_checkfile(path: &Path, args: &Args, files_failed: &mut u64) -> Resu
// return, so it doesn't return a Result.
let success = check_one_line(&line, args);
if !success {
*files_failed += 1;
// We use `files_failed > 0` to indicate a mismatch, so it's important for correctness
// that it's impossible for this counter to overflow.
*files_failed = files_failed.saturating_add(1);
}
}
}
@ -582,7 +584,12 @@ fn main() -> Result<()> {
}
}
if args.check() && files_failed > 0 {
eprintln!("{}: WARNING {} computed checksum{} did NOT match", NAME, files_failed, if files_failed == 1 {""} else {"s"});
eprintln!(
"{}: WARNING {} computed checksum{} did NOT match",
NAME,
files_failed,
if files_failed == 1 { "" } else { "s" },
);
}
std::process::exit(if files_failed > 0 { 1 } else { 0 });
})