Skip to content

Commit

Permalink
impl: eliminate panic on overflowing absolute value
Browse files Browse the repository at this point in the history
Fixes #268 (again)
  • Loading branch information
jhpratt committed Jan 15, 2021
1 parent 4b11ba8 commit 32d8b03
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/arbitrary.rs
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/tester.rs
Expand Up @@ -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);
Expand Down

0 comments on commit 32d8b03

Please sign in to comment.