1
Fork 0

Check that we don't access nonexisting union fields

This commit is contained in:
Oliver Scherer 2019-10-10 18:21:34 +02:00
parent 76fe6a41ba
commit 373c362b7e

View file

@ -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);