aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2025-03-28 18:06:14 +0000
committerPhilip Herron <philip.herron@embecosm.com>2025-03-28 20:04:18 +0000
commit1d93ebb1cad42c38119ec74ab5587d08c29825f2 (patch)
treeff3ad147656ad0a3f91163dac3134aba4efdef1f /gcc/rust
parent8b5f1f296b60f9343ed995f14552d022f077e1f6 (diff)
downloadgcc-1d93ebb1cad42c38119ec74ab5587d08c29825f2.zip
gcc-1d93ebb1cad42c38119ec74ab5587d08c29825f2.tar.gz
gcc-1d93ebb1cad42c38119ec74ab5587d08c29825f2.tar.bz2
gccrs: fix crash in parse repr options and missing delete call
Fixes Rust-GCC#3606 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::parse_repr_options): check for null and empty and add missing delete call gcc/testsuite/ChangeLog: * rust/compile/issue-3606.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-base.cc20
1 files changed, 18 insertions, 2 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-base.cc b/gcc/rust/typecheck/rust-hir-type-check-base.cc
index f60b540..378ef02 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-base.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-base.cc
@@ -321,8 +321,22 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec &attrs, location_t locus)
AST::AttrInputMetaItemContainer *meta_items
= option.parse_to_meta_item ();
- const std::string inline_option
- = meta_items->get_items ().at (0)->as_string ();
+ if (meta_items == nullptr)
+ {
+ rust_error_at (attr.get_locus (), "malformed %qs attribute",
+ "repr");
+ continue;
+ }
+
+ auto &items = meta_items->get_items ();
+ if (items.size () == 0)
+ {
+ // nothing to do with this its empty
+ delete meta_items;
+ continue;
+ }
+
+ const std::string inline_option = items.at (0)->as_string ();
// TODO: it would probably be better to make the MetaItems more aware
// of constructs with nesting like #[repr(packed(2))] rather than
@@ -359,6 +373,8 @@ TypeCheckBase::parse_repr_options (const AST::AttrVec &attrs, location_t locus)
else if (is_align)
repr.align = value;
+ delete meta_items;
+
// Multiple repr options must be specified with e.g. #[repr(C,
// packed(2))].
break;