Skip to content

Commit 946a396

Browse files
committed
test: Fix an overflow on empty benchmarks
Right now the rust upgrade in cargo is blocked on fixing this overflow. If a this benchmark is run it will trigger an overflow error today: #[bench] fn foo(b: &mut test::Bencher) {} This commit adds a check on each iteration of the loop that the maximum multiplier (10) doesn't overflow, and if it does just return the results so far.
1 parent 1fe8f22 commit 946a396

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/libtest/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,14 @@ impl Bencher {
11081108
return summ5;
11091109
}
11101110

1111-
n *= 2;
1111+
// If we overflow here just return the results so far. We check a
1112+
// multiplier of 10 because we're about to multiply by 2 and the
1113+
// next iteration of the loop will also multiply by 5 (to calculate
1114+
// the summ5 result)
1115+
n = match n.checked_mul(10) {
1116+
Some(_) => n * 2,
1117+
None => return summ5,
1118+
};
11121119
}
11131120
}
11141121
}

0 commit comments

Comments
 (0)