Skip to content

Commit b2f09c1

Browse files
committed
Auto merge of #23127 - alexcrichton:bench-wrapping, r=brson
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.
2 parents d30609f + 946a396 commit b2f09c1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/libtest/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,14 @@ impl Bencher {
11091109
return summ5;
11101110
}
11111111

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

0 commit comments

Comments
 (0)