Skip to content

Commit

Permalink
Auto merge of #23127 - alexcrichton:bench-wrapping, r=brson
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Mar 8, 2015
2 parents d30609f + 946a396 commit b2f09c1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,14 @@ impl Bencher {
return summ5;
}

n *= 2;
// If we overflow here just return the results so far. We check a
// multiplier of 10 because we're about to multiply by 2 and the
// next iteration of the loop will also multiply by 5 (to calculate
// the summ5 result)
n = match n.checked_mul(10) {
Some(_) => n * 2,
None => return summ5,
};
}
}
}
Expand Down

0 comments on commit b2f09c1

Please sign in to comment.