]> git.gag.com Git - fw/sdcc/commitdiff
Fixed bug #748310 (pointer to function type mishandled when the
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 16 Aug 2003 07:58:46 +0000 (07:58 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 16 Aug 2003 07:58:46 +0000 (07:58 +0000)
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
src/SDCC.y
support/Util/SDCCerr.c
support/Util/SDCCerr.h

index 17352c3ae391d9a68f118fc8517ca47315a395a6..201d74c7d5266c122c11174677d8ddb84e21f17c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2003-08-16  Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
+       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 <bernhard@bernhardheld.de>
 
        Fixed bug #787649 by anonymous
index 8107bd016ce0ef957f53a4c07d99cc09f5587798..9b6492e9891ecb20e8eec10c4967f13c8ae6c707 100644 (file)
@@ -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);
    }
    ;
 
index c48877bbf811486cc0ef18556699488ac72948ee..b28bd7db3ea73257d6dd250b3e96762b791e63cd 100644 (file)
@@ -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"},
 };
 
 /*
index 30bb73ea64e6006cd42cdb70a27f12c509177aaa..a2ed448dc680833af19face03bbeb97805aa1148 100644 (file)
@@ -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.