From ad86e4679a588ff7d9050aaa9994dc6c768dbe59 Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 6 Dec 2003 13:35:05 +0000 Subject: [PATCH] Make struct work as documented git-svn-id: svn://svn.cc65.org/cc65/trunk@2716 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/struct.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/ca65/struct.c b/src/ca65/struct.c index 307171d8a..583d63389 100644 --- a/src/ca65/struct.c +++ b/src/ca65/struct.c @@ -83,6 +83,11 @@ static long Member (long AllocSize) AllocSize *= Multiplicator; } + /* Check the size for a reasonable value */ + if (AllocSize >= 0x10000) { + Error ("Range error"); + } + /* Return the size */ return AllocSize; } @@ -99,13 +104,7 @@ static long DoStructInternal (long Offs, unsigned Type) * is started. */ int Anon = (Tok != TOK_IDENT); - if (Anon) { - unsigned char T = GetCurrentSymTabType (); - if (T != ST_STRUCT) { - ErrorSkip ("Struct/union needs a name"); - return 0; - } - } else { + if (!Anon) { /* Enter a new scope, then skip the name */ SymEnterLevel (SVal, ST_STRUCT, ADDR_SIZE_ABS); NextTok (); @@ -178,10 +177,8 @@ static long DoStructInternal (long Offs, unsigned Type) Error ("Not a struct/union"); } else { SymEntry* SizeSym = GetSizeOfScope (Struct); - if (!SymIsDef (SizeSym)) { + if (!SymIsDef (SizeSym) || !SymIsConst (SizeSym, &MemberSize)) { Error ("Size of struct/union is unknown"); - } else { - MemberSize = GetSymVal (SizeSym); } } MemberSize *= Member (MemberSize); -- 2.39.5