From a789b8913527f2893d3258ae5fa1cae28d44b2c9 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Tue, 4 May 2021 16:33:08 -0600 Subject: [PATCH] Check both u64 max and min in ValueSum arithemetic. --- src/value.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/value.rs b/src/value.rs index 51d6f811..c96000e1 100644 --- a/src/value.rs +++ b/src/value.rs @@ -69,11 +69,12 @@ impl NoteValue { impl Sub for NoteValue { type Output = Option; + #[allow(clippy::suspicious_arithmetic_impl)] fn sub(self, rhs: Self) -> Self::Output { let a = self.0 as i128; let b = rhs.0 as i128; a.checked_sub(b) - .filter(|v| v > &(-(std::u64::MAX as i128))) + .filter(|v| v > &(-(std::u64::MAX as i128)) && v < &(std::u64::MAX as i128)) .map(ValueSum) } } @@ -100,10 +101,11 @@ impl ValueSum { impl Add for ValueSum { type Output = Option; + #[allow(clippy::suspicious_arithmetic_impl)] fn add(self, rhs: Self) -> Self::Output { self.0 .checked_add(rhs.0) - .filter(|v| v < &(std::u64::MAX as i128)) + .filter(|v| v > &(-(std::u64::MAX as i128)) && v < &(std::u64::MAX as i128)) .map(ValueSum) } }