Skip to content

Commit 03dc323

Browse files
committed
Avoid possible integer overflow in niche value computation
@eddyb pointed out in review that the niche value computation had a possible integer overflow problem, fixed here as he suggested.
1 parent 5117270 commit 03dc323

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/librustc_codegen_llvm/debuginfo/metadata.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1374,8 +1374,11 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
13741374
let niche_value = if i == dataful_variant {
13751375
None
13761376
} else {
1377-
Some((i.wrapping_sub(*niche_variants.start()) as u128)
1378-
.wrapping_add(niche_start) as u64)
1377+
let niche = (i as u128)
1378+
.wrapping_sub(*niche_variants.start() as u128)
1379+
.wrapping_add(niche_start);
1380+
assert_eq!(niche as u64 as u128, niche);
1381+
Some(niche as u64)
13791382
};
13801383

13811384
MemberDescription {

0 commit comments

Comments
 (0)