From f5b1b69376f978223dfabe535f23a5ec03bb3dc2 Mon Sep 17 00:00:00 2001 From: acqn Date: Sat, 15 Aug 2020 06:27:11 +0800 Subject: [PATCH] Forbid struct/union fields of incomplete types. --- src/cc65/declare.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/cc65/declare.c b/src/cc65/declare.c index ccd4e9004..6c1dbd751 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -911,8 +911,15 @@ static SymEntry* ParseUnionDecl (const char* Name) } } + /* Check for incomplete type */ + if (IsIncompleteESUType (Decl.Type)) { + Error ("Field '%s' has incomplete type '%s'", + Decl.Ident, + GetFullTypeName (Decl.Type)); + } + /* Handle sizes */ - FieldSize = CheckedSizeOf (Decl.Type); + FieldSize = SizeOf (Decl.Type); if (FieldSize > UnionSize) { UnionSize = FieldSize; } @@ -1095,6 +1102,13 @@ static SymEntry* ParseStructDecl (const char* Name) } } + /* Check for incomplete type */ + if (IsIncompleteESUType (Decl.Type)) { + Error ("Field '%s' has incomplete type '%s'", + Decl.Ident, + GetFullTypeName (Decl.Type)); + } + /* Add a field entry to the table */ if (FieldWidth > 0) { /* Full bytes have already been added to the StructSize, @@ -1119,7 +1133,7 @@ static SymEntry* ParseStructDecl (const char* Name) AddLocalSym (Decl.Ident, Decl.Type, SC_STRUCTFIELD, StructSize); } if (!FlexibleMember) { - StructSize += CheckedSizeOf (Decl.Type); + StructSize += SizeOf (Decl.Type); } }