Use saturating arithmetic on calculating row saving

The saturating arithmetic doesn't overflow, but stays at the maximum or
minimum. In this case it doesn't become negative, but zero, which
satisfies the condition below.

Closes #31
This commit is contained in:
Jörg Sommer
2021-05-13 17:12:33 +02:00
parent b33c498e99
commit 4f823fba78

View File

@@ -229,7 +229,7 @@ fn main() {
); );
if let Some(min) = min_saved_rows { if let Some(min) = min_saved_rows {
let saving = (original_summed_size - compressed_summed_size) as i32; let saving = original_summed_size.saturating_sub(compressed_summed_size);
if saving < min { if saving < min {
println!( println!(
"Only {} rows would be saved by this compression. Skipping output.", "Only {} rows would be saved by this compression. Skipping output.",