fixed bug #585125
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 10 May 2003 13:44:38 +0000 (13:44 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 10 May 2003 13:44:38 +0000 (13:44 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2605 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCglue.c

index cf53707894e5125e3f42847a96fabc2ae1814321..065a56a4b7e5054ece3020af1d469141d1a6cb3b 100644 (file)
@@ -784,8 +784,7 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist,
                FILE * oFile)
 {
   initList *iloop;
-  int lcnt = 0, size = 0;
-  sym_link *last_type;
+  int size = 0;
 
   /* take care of the special   case  */
   /* array of characters can be init  */
@@ -807,40 +806,28 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist,
       return;
     }
 
-  iloop = ilist->init.deep;
-  lcnt = DCL_ELEM (type);
-  for (last_type = type->next; 
-       last_type && IS_DECL(last_type) && DCL_ELEM (last_type); 
-       last_type = last_type->next) {
-    lcnt *= DCL_ELEM (last_type);
-  }
-
-  for (;;)
+  for (iloop=ilist->init.deep; iloop; iloop=iloop->next)
     {
-      size++;
       printIval (sym, type->next, iloop, oFile);
-      iloop = (iloop ? iloop->next : NULL);
-
-
-      /* if not array limits given & we */
-      /* are out of initialisers then   */
-      if (!DCL_ELEM (type) && !iloop)
-       break;
-
-      /* no of elements given and we    */
-      /* have generated for all of them */
-      if (!--lcnt) {
-       /* if initializers left */
-       if (iloop) {
-         werror (W_EXCESS_INITIALIZERS, "array", sym->name, sym->lineDef);
-       }
+      
+      if (++size > DCL_ELEM(type)) {
+       werror (W_EXCESS_INITIALIZERS, "array", sym->name, sym->lineDef);
        break;
       }
     }
-
-  /* if we have not been given a size  */
-  if (!DCL_ELEM (type))
+  
+  if (DCL_ELEM(type)) {
+    // pad with zeros if needed
+    if (size<DCL_ELEM(type)) {
+      size = (DCL_ELEM(type) - size) * getSize(type->next);
+      while (size--) {
+       tfprintf (oFile, "\t!db !constbyte\n", 0);
+      }
+    }
+  } else {
+    // we have not been given a size, but we now know it
     DCL_ELEM (type) = size;
+  }
 
   return;
 }