Skip to content

Commit

Permalink
Avoid possible integer overflow in niche value computation
Browse files Browse the repository at this point in the history
@eddyb pointed out in review that the niche value computation had a
possible integer overflow problem, fixed here as he suggested.
  • Loading branch information
tromey committed Oct 30, 2018
1 parent e7c49a7 commit da7b6b4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/librustc_codegen_llvm/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,8 +1361,11 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
let niche_value = if i == dataful_variant {
None
} else {
Some((i.wrapping_sub(*niche_variants.start()) as u128)
.wrapping_add(niche_start) as u64)
let niche = (i as u128)
.wrapping_sub(*niche_variants.start() as u128)
.wrapping_add(niche_start);
assert_eq!(niche as u64 as u128, niche);
Some(niche as u64)
};

MemberDescription {
Expand Down

0 comments on commit da7b6b4

Please sign in to comment.