From 373c362b7ed0df2dfbc21853e53d5082f20d3de8 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Thu, 10 Oct 2019 18:21:34 +0200 Subject: [PATCH] Check that we don't access nonexisting union fields --- src/librustc_target/abi/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs index 26d37f196bef..fde5c5bed4d9 100644 --- a/src/librustc_target/abi/mod.rs +++ b/src/librustc_target/abi/mod.rs @@ -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);