From b6d540887cbb3f18a4e60583f783c7c9cafcfb31 Mon Sep 17 00:00:00 2001 From: epetrich Date: Sat, 16 Aug 2003 07:58:46 +0000 Subject: [PATCH] Fixed bug #748310 (pointer to function type mishandled when the function name is omitted). Also fixed a SIGSEGV when a function attribute (reentrant, etc) is used on a non-function or on a function but misplaced before the parameter list. * src/SDCC.y (abstract_declarator, abstract_declaractor2): fixed bug #748310 * src/SDCC.y (declarator2_function_attributes): avoided SIGSEGV * support/Util/SDCCerr.h, * support/Util/SDCCerr.c: Added func attr misuse error msg git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2829 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 13 ++++++++ src/SDCC.y | 74 ++++++++++++++++++++++++------------------ support/Util/SDCCerr.c | 2 ++ support/Util/SDCCerr.h | 1 + 4 files changed, 59 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index 17352c3a..201d74c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2003-08-16 Erik Petrich + + Fixed bug #748310 (pointer to function type mishandled when the + function name is omitted). Also fixed a SIGSEGV when a function + attribute (reentrant, etc) is used on a non-function or on a + function but misplaced before the parameter list. + + * src/SDCC.y (abstract_declarator, abstract_declaractor2): fixed + bug #748310 + * src/SDCC.y (declarator2_function_attributes): avoided SIGSEGV + * support/Util/SDCCerr.h, + * support/Util/SDCCerr.c: Added func attr misuse error msg + 2003-08-13 Bernhard Held Fixed bug #787649 by anonymous diff --git a/src/SDCC.y b/src/SDCC.y index 8107bd01..9b6492e9 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -928,22 +928,32 @@ declarator declarator2_function_attributes : declarator2 { $$ = $1 ; } | declarator2 function_attribute { - // copy the functionAttributes (not the args and hasVargs !!) - sym_link *funcType=$1->etype; - struct value *args=FUNC_ARGS(funcType); - unsigned hasVargs=FUNC_HASVARARGS(funcType); - - memcpy (&funcType->funcAttrs, &$2->funcAttrs, - sizeof($2->funcAttrs)); - - FUNC_ARGS(funcType)=args; - FUNC_HASVARARGS(funcType)=hasVargs; - - // just to be sure - memset (&$2->funcAttrs, 0, - sizeof($2->funcAttrs)); - - addDecl ($1,0,$2); + if ((! $1) || (! IS_FUNC($1->etype))) + { + // function_attribute is only allowed if declarator2 was + // an actual function + werror(E_FUNC_ATTR); + $$=$1; + } + else + { + // copy the functionAttributes (not the args and hasVargs !!) + sym_link *funcType=$1->etype; + struct value *args=FUNC_ARGS(funcType); + unsigned hasVargs=FUNC_HASVARARGS(funcType); + + memcpy (&funcType->funcAttrs, &$2->funcAttrs, + sizeof($2->funcAttrs)); + + FUNC_ARGS(funcType)=args; + FUNC_HASVARARGS(funcType)=hasVargs; + + // just to be sure + memset (&$2->funcAttrs, 0, + sizeof($2->funcAttrs)); + + addDecl ($1,0,$2); + } } ; @@ -1153,7 +1163,10 @@ type_name abstract_declarator : pointer { $$ = reverseLink($1); } | abstract_declarator2 - | pointer abstract_declarator2 { $1 = reverseLink($1); $1->next = $2 ; $$ = $1;} + | pointer abstract_declarator2 { $1 = reverseLink($1); $1->next = $2 ; $$ = $1; + if (IS_PTR($1) && IS_FUNC($2)) + DCL_TYPE($1) = CPOINTER; + } ; abstract_declarator2 @@ -1197,22 +1210,21 @@ abstract_declarator2 } $1->next=p; } - | abstract_declarator2 '(' parameter_type_list ')' { - if (!IS_VOID($3->etype)) { - // this is nonsense, so let's just burp something - werror(E_TOO_FEW_PARMS); - } else { - // $1 must be a pointer to a function + | abstract_declarator2 '(' { NestLevel++ ; currBlockno++; } parameter_type_list ')' { sym_link *p=newLink(DECLARATOR); DCL_TYPE(p) = FUNCTION; - if (!$1) { - // ((void (code *) (void)) 0) () - $1=newLink(DECLARATOR); - DCL_TYPE($1)=CPOINTER; - $$ = $1; - } - $1->next=p; - } + + FUNC_HASVARARGS(p) = IS_VARG($4); + FUNC_ARGS(p) = reverseVal($4); + + /* nest level was incremented to take care of the parms */ + NestLevel-- ; + currBlockno--; + p->next = $1; + $$ = p; + + // remove the symbol args (if any) + cleanUpLevel(SymbolTab,NestLevel+1); } ; diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index c48877bb..b28bd7db 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -393,6 +393,8 @@ struct "interrupt number '%u' is not valid" }, { W_BITFLD_NAMED, ERROR_LEVEL_WARNING, "ignoring declarator of 0 length bitfield" }, +{ E_FUNC_ATTR, ERROR_LEVEL_ERROR, + "function attribute following non-function declaration"}, }; /* diff --git a/support/Util/SDCCerr.h b/support/Util/SDCCerr.h index 30bb73ea..a2ed448d 100644 --- a/support/Util/SDCCerr.h +++ b/support/Util/SDCCerr.h @@ -184,6 +184,7 @@ SDCCERR - SDCC Standard error handler #define W_USELESS_DECL 166 /* useless declaration */ #define E_INT_BAD_INTNO 167 /* invalid interrupt number */ #define W_BITFLD_NAMED 168 /* declarator used with 0 length bitfield */ +#define E_FUNC_ATTR 169 /* function attribute without function */ /** Describes the maximum error level that will be logged. Any level * includes all of the levels listed after it. -- 2.47.2