From 32d8b0383b5cedb5e6dd8fd3dd1494f734e49d6e Mon Sep 17 00:00:00 2001 From: Jacob Pratt Date: Fri, 15 Jan 2021 07:44:24 -0500 Subject: [PATCH] impl: eliminate panic on overflowing absolute value Fixes #268 (again) --- src/arbitrary.rs | 4 +++- src/tester.rs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/arbitrary.rs b/src/arbitrary.rs index 13b5b65..92f893b 100644 --- a/src/arbitrary.rs +++ b/src/arbitrary.rs @@ -824,7 +824,9 @@ macro_rules! signed_shrinker { impl Iterator for SignedShrinker { type Item = $ty; fn next(&mut self) -> Option<$ty> { - if (self.x - self.i).abs() < self.x.abs() { + if self.x == <$ty>::MIN + || (self.x - self.i).abs() < self.x.abs() + { let result = Some(self.x - self.i); self.i = self.i / 2; result diff --git a/src/tester.rs b/src/tester.rs index bd0e4e6..e2eaa20 100644 --- a/src/tester.rs +++ b/src/tester.rs @@ -443,7 +443,7 @@ mod test { #[test] fn regression_signed_shrinker_panic() { fn foo_can_shrink(v: i8) -> bool { - let _ = crate::Arbitrary::shrink(&v); + let _ = crate::Arbitrary::shrink(&v).take(100).count(); true } crate::quickcheck(foo_can_shrink as fn(i8) -> bool);