fixed bug #436360 part 1 and 3
[fw/sdcc] / src / SDCCsymt.c
index fe7223a8323d0a97efbbd23a34ab14a3ef3c8db8..77b03a7539247133beb29bf3eab3ec6309e17c70 100644 (file)
@@ -72,7 +72,7 @@ newBucket ()
 {
   bucket *bp;
 
-  bp = Safe_calloc (1, sizeof (bucket));
+  bp = Safe_alloc ( sizeof (bucket));
 
   return bp;
 }
@@ -112,10 +112,16 @@ addSym (bucket ** stab,
     checkTypeSanity(((symbol *)sym)->etype, ((symbol *)sym)->name);
   }
 
+  /* prevent overflow of the (r)name buffers */
+  if (strlen(sname)>SDCC_SYMNAME_MAX) {
+    werror (W_SYMBOL_NAME_TOO_LONG, SDCC_SYMNAME_MAX);
+    sname[SDCC_SYMNAME_MAX]='\0';
+  }
+
   /* the symbols are always added at the head of the list  */
   i = hashKey (sname);
   /* get a free entry */
-  bp = Safe_calloc (1, sizeof (bucket));
+  bp = Safe_alloc ( sizeof (bucket));
 
   bp->sym = sym;               /* update the symbol pointer  */
   bp->level = level;           /* update the nest level      */
@@ -267,7 +273,7 @@ newSymbol (char *name, int scope)
 {
   symbol *sym;
 
-  sym = Safe_calloc (1, sizeof (symbol));
+  sym = Safe_alloc ( sizeof (symbol));
 
   strcpy (sym->name, name);    /* copy the name    */
   sym->level = scope;          /* set the level    */
@@ -284,7 +290,7 @@ newLink ()
 {
   sym_link *p;
 
-  p = Safe_calloc (1, sizeof (sym_link));
+  p = Safe_alloc ( sizeof (sym_link));
 
   return p;
 }
@@ -297,7 +303,7 @@ newStruct (char *tag)
 {
   structdef *s;
 
-  s = Safe_calloc (1, sizeof (structdef));
+  s = Safe_alloc ( sizeof (structdef));
 
   strcpy (s->tag, tag);                /* copy the tag            */
   return s;
@@ -1418,10 +1424,14 @@ computeType (sym_link * type1, sym_link * type2)
 
   reType = getSpec (rType);
 
-  /* if either of them unsigned then make this unsigned */
-  if ((SPEC_USIGN (etype1) || SPEC_USIGN (etype2)) && !IS_FLOAT (reType))
+  /* if either of them unsigned but not val then make this unsigned */
+  if (((!IS_LITERAL(type1) && SPEC_USIGN (etype1)) || 
+       (!IS_LITERAL(type2) && SPEC_USIGN (etype2))) && 
+      !IS_FLOAT (reType))
     SPEC_USIGN (reType) = 1;
-
+  else
+    SPEC_USIGN (reType) = 0;
+  
   /* if result is a literal then make not so */
   if (IS_LITERAL (reType))
     SPEC_SCLS (reType) = S_REGISTER;
@@ -1536,6 +1546,8 @@ inCalleeSaveList (char *s)
 void 
 aggregateArgToPointer (value * val)
 {
+  int wasArray=IS_ARRAY(val->type);
+
   if (IS_AGGREGATE (val->type))
     {
       /* if this is a structure */
@@ -1588,6 +1600,12 @@ aggregateArgToPointer (value * val)
        default:
          DCL_TYPE (val->type) = GPOINTER;
        }
+      
+      if (wasArray) {
+       /* there is NO way to specify the storage of the pointer
+          associated with an array, so we make it the default */
+       SPEC_SCLS(val->etype) = S_FIXED;
+      }
 
       /* is there is a symbol associated then */
       /* change the type of the symbol as well */
@@ -1688,7 +1706,7 @@ checkFunction (symbol * sym)
       werror (E_PREV_DEF_CONFLICT, csym->name, "_naked");
     }
 
-  /* compare expected agrs with actual args */
+  /* compare expected args with actual args */
   exargs = csym->args;
   acargs = sym->args;
 
@@ -1883,6 +1901,11 @@ printTypeChain (sym_link * start, FILE * of)
       nlr = 1;
     }
 
+  if (start==NULL) {
+    fprintf (of, "**err**");
+    return;
+  }
+
   /* print the chain as it is written in the source: */
   /* start with the last entry                       */
   for (type = start; type && type->next; type = type->next)