Skip to content

Commit

Permalink
Check that we don't access nonexisting union fields
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Oct 10, 2019
1 parent 76fe6a4 commit 373c362
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/librustc_target/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,11 @@ impl FieldPlacement {

pub fn offset(&self, i: usize) -> Size {
match *self {
FieldPlacement::Union(_) => Size::ZERO,
FieldPlacement::Union(count) => {
assert!(i < count,
"Tried to access field {} of union with {} fields", i, count);
Size::ZERO
},
FieldPlacement::Array { stride, count } => {
let i = i as u64;
assert!(i < count);
Expand Down

0 comments on commit 373c362

Please sign in to comment.