Skip to content

Commit 155cf2e

Browse files
committed
coverage: Avoid overflow when the MC/DC condition limit is exceeded
If we perform this subtraction first, it can sometimes overflow to -1 before the addition can bring its value back to 0. That behaviour seems to be benign, but it nevertheless causes test failures in compiler configurations that check for overflow.
1 parent da159eb commit 155cf2e

File tree

1 file changed

+1
-1
lines changed
  • compiler/rustc_mir_build/src/build/coverageinfo

1 file changed

+1
-1
lines changed

compiler/rustc_mir_build/src/build/coverageinfo/mcdc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl MCDCInfoBuilder {
217217
}
218218
_ => {
219219
// Do not generate mcdc mappings and statements for decisions with too many conditions.
220-
let rebase_idx = self.branch_spans.len() - decision.conditions_num + 1;
220+
let rebase_idx = self.branch_spans.len() + 1 - decision.conditions_num;
221221
for branch in &mut self.branch_spans[rebase_idx..] {
222222
branch.condition_info = None;
223223
}

0 commit comments

Comments
 (0)