* src/pic16/glue.c (printIvalChar): fixed bug when emitting
authorvrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 10 Apr 2005 16:08:23 +0000 (16:08 +0000)
committervrokas <vrokas@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 10 Apr 2005 16:08:23 +0000 (16:08 +0000)
characters arrays of larger size than the declared one.

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3731 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/pic16/glue.c

index 5fac77585b7626c05fa22fb2d66a438bbe6bf2b0..66d5964383bb70929c4fc89ec383de40303e10a5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-04-10 Vangelis Rokas <vrokas AT users.sourceforge.net>
+
+       * src/pic16/glue.c (printIvalChar): fixed bug when emitting
+       characters arrays of larger size than the declared one.
+
 2005-04-10 Borut Razem <borut.razem AT siol.net>
 
        * src/pic/gen.c (genInline),
index 6898b5c29a7f30a143e0638ccef03e7b58d8aa35..0b6b4fd6d0a4b1fe55f0ab2128a2ae8e84998285 100644 (file)
@@ -634,10 +634,10 @@ pic16_printIvalType (symbol *sym, sym_link * type, initList * ilist, char ptype,
 /* pic16_printIvalChar - generates initital value for character array */
 /*--------------------------------------------------------------------*/
 static int 
-pic16_printIvalChar (sym_link * type, initList * ilist, char *s, char ptype, void *p)
+pic16_printIvalChar (symbol *sym, sym_link * type, initList * ilist, char *s, char ptype, void *p)
 {
   value *val;
-  unsigned int remain;
+  int remain, len;
 
   if(!p)
     return 0;
@@ -653,14 +653,38 @@ pic16_printIvalChar (sym_link * type, initList * ilist, char *s, char ptype, voi
       if(!DCL_ELEM (type))
         DCL_ELEM (type) = strlen (SPEC_CVAL (val->etype).v_char) + 1;
 
-      for(remain=0; remain<strlen(SPEC_CVAL(val->etype).v_char)+1; remain++)
-        pic16_emitDB(SPEC_CVAL(val->etype).v_char[ remain ], ptype, p);
-      
-      if((remain = (DCL_ELEM (type) - strlen (SPEC_CVAL (val->etype).v_char) - 1)) > 0) {
-        while(remain--) {
+      /* len is 0 if declartion equals initializer,
+       * >0 if declaration greater than initializer
+       * <0 if declaration less than initializer
+       * Strategy: if >0 emit 0x00 for the rest of the length,
+       * if <0 then emit only the length of declaration elements
+       * and warn user
+       */
+      len = DCL_ELEM (type) - (strlen (SPEC_CVAL (val->etype).v_char)+1);
+
+//      fprintf(stderr, "%s:%d len = %i DCL_ELEM(type) = %i SPEC_CVAL-len = %i\n", __FILE__, __LINE__,
+//        len, DCL_ELEM(type), strlen(SPEC_CVAL(val->etype).v_char));
+
+      remain=0;
+      if(len >= 0) {
+        for(remain=0; remain<strlen(SPEC_CVAL(val->etype).v_char)+1; remain++)
+          pic16_emitDB(SPEC_CVAL(val->etype).v_char[ remain ], ptype, p);
+
+        len -= remain;
+        while(len--) {
           pic16_emitDB(0x00, ptype, p);
         }
+
+      } else {
+        werror (W_EXCESS_INITIALIZERS, "array of chars", sym->name, sym->lineDef);
+
+        for(remain=0; remain<DCL_ELEM (type); remain++)
+          pic16_emitDB(SPEC_CVAL(val->etype).v_char[ remain ], ptype, p);
       }
+      
+
+//      if((remain = (DCL_ELEM (type) - strlen (SPEC_CVAL (val->etype).v_char) - 1)) > 0) {
+//      }
       return 1;
     } else return 0;
   } else {
@@ -697,7 +721,7 @@ pic16_printIvalArray (symbol * sym, sym_link * type, initList * ilist,
       return;
     }
 
-    if(pic16_printIvalChar (type,
+    if(pic16_printIvalChar (sym, type,
                       (ilist->type == INIT_DEEP ? ilist->init.deep : ilist),
                       SPEC_CVAL (sym->etype).v_char, ptype, p))
       return;