From 4f823fba78361c721c03af585150a293187549c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sommer?= Date: Thu, 13 May 2021 17:12:33 +0200 Subject: [PATCH] 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 --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 9f276da..71f85e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -229,7 +229,7 @@ fn main() { ); 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 { println!( "Only {} rows would be saved by this compression. Skipping output.",