Skip to content

Commit 32d8b03

Browse files
authored
impl: eliminate panic on overflowing absolute value
Fixes BurntSushi#268 (again)
1 parent 4b11ba8 commit 32d8b03

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/arbitrary.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,9 @@ macro_rules! signed_shrinker {
824824
impl Iterator for SignedShrinker {
825825
type Item = $ty;
826826
fn next(&mut self) -> Option<$ty> {
827-
if (self.x - self.i).abs() < self.x.abs() {
827+
if self.x == <$ty>::MIN
828+
|| (self.x - self.i).abs() < self.x.abs()
829+
{
828830
let result = Some(self.x - self.i);
829831
self.i = self.i / 2;
830832
result

src/tester.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ mod test {
443443
#[test]
444444
fn regression_signed_shrinker_panic() {
445445
fn foo_can_shrink(v: i8) -> bool {
446-
let _ = crate::Arbitrary::shrink(&v);
446+
let _ = crate::Arbitrary::shrink(&v).take(100).count();
447447
true
448448
}
449449
crate::quickcheck(foo_can_shrink as fn(i8) -> bool);

0 commit comments

Comments
 (0)