aboutsummaryrefslogtreecommitdiff
path: root/b3sum
diff options
context:
space:
mode:
authorJack O'Connor <[email protected]>2023-02-04 09:59:01 -0800
committerJack O'Connor <[email protected]>2023-02-04 10:15:25 -0800
commitf1dcbeadc238c940d0dcfa3608afee16c950685f (patch)
tree0dc6618f5dd4edfd6726b1eaec242c59504580da /b3sum
parent98135307bf00c8dee991b016c2117c913fc18a47 (diff)
do a saturating_add for files_failed
Diffstat (limited to 'b3sum')
-rw-r--r--b3sum/src/main.rs11
1 files changed, 9 insertions, 2 deletions
diff --git a/b3sum/src/main.rs b/b3sum/src/main.rs
index 8ef1bec..c44e11b 100644
--- a/b3sum/src/main.rs
+++ b/b3sum/src/main.rs
@@ -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 });
})