* src/pic16/glue.c (pic16_printIvalChar): fixed _constant_ string
authortecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 26 May 2005 21:52:37 +0000 (21:52 +0000)
committertecodev <tecodev@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 26 May 2005 21:52:37 +0000 (21:52 +0000)
  initializers with \0, bug #1208187
* src/pic/glue.c (printIvalChar): fixed (non- and constant) string
  intializers with \0, bug #1208187

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

ChangeLog
src/pic/glue.c
src/pic16/glue.c

index 7de1ae314491b33d683bf8fedada036072a4c867..ea242ced697ff1669ab1b81e296ff58634e8f164 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-05-26 Raphael Neider <rneider AT web.de>
+
+       * src/pic16/glue.c (pic16_printIvalChar): fixed _constant_ string
+         initializers with \0, bug #1208187
+       * src/pic/glue.c (printIvalChar): fixed (non- and constant) string
+         intializers with \0, bug #1208187
+
 2005-05-26 Raphael Neider <rneider AT web.de>
 
        * src/pic16/glue.c (pic16_printIvalChar): fixed string
index 4a36acd75834d28388a3e3d7b134116e0b01174e..85d49a3a8495e55a82336710034aa7e623cb2631 100644 (file)
@@ -369,7 +369,7 @@ static int
 printIvalChar (sym_link * type, initList * ilist, pBlock *pb, char *s)
 {
        value *val;
-       int remain;
+       int remain, ilen;
        
        if(!pb)
                return 0;
@@ -379,17 +379,22 @@ printIvalChar (sym_link * type, initList * ilist, pBlock *pb, char *s)
        {
                
                val = list2val (ilist);
+
                /* if the value is a character string  */
                if (IS_ARRAY (val->type) && IS_CHAR (val->etype))
                {
+                       ilen = DCL_ELEM(val->type);
+
                        if (!DCL_ELEM (type))
-                               DCL_ELEM (type) = strlen (SPEC_CVAL (val->etype).v_char) + 1;
-                       
-                       //printChar (oFile, SPEC_CVAL (val->etype).v_char, DCL_ELEM (type));
-                       //fprintf(stderr, "%s omitting call to printChar\n",__FUNCTION__);
-                       addpCode2pBlock(pb,newpCodeCharP(";omitting call to printChar"));
+                               DCL_ELEM (type) = ilen;
+               
+                       /* emit string constant */
+                       for (remain = 0; remain < ilen; remain++) {
+                               addpCode2pBlock(pb,newpCode(POC_RETLW,newpCodeOpLit(SPEC_CVAL(val->etype).v_char[remain])));
+                       }
                        
-                       if ((remain = (DCL_ELEM (type) - strlen (SPEC_CVAL (val->etype).v_char) - 1)) > 0)
+                       /* fill array up to desired size */
+                       if ((remain = (DCL_ELEM (type) - ilen)) > 0)
                                while (remain--)
                                        //tfprintf (oFile, "\t!db !constbyte\n", 0);
                                        addpCode2pBlock(pb,newpCode(POC_RETLW,newpCodeOpLit(0)));
index c35c02222b1fe28f61dcfead7abb2e79ab2c9d13..7e1d1b762de80a2aaa61c0d7d5327a577230146d 100644 (file)
@@ -648,12 +648,13 @@ pic16_printIvalChar (symbol *sym, sym_link * type, initList * ilist, char *s, ch
 #endif
 
   if(!s) {
-    /* length of initializer string (might contain \0, so do not use strlen) */
-    ilen = getNelements (type, ilist);
-
     val = list2val (ilist);
+
     /* if the value is a character string  */
     if(IS_ARRAY (val->type) && IS_CHAR (val->etype)) {
+      /* length of initializer string (might contain \0, so do not use strlen) */
+      ilen = DCL_ELEM(val->type);
+
       if(!DCL_ELEM (type))
         DCL_ELEM (type) = ilen;