From: tecodev Date: Thu, 26 May 2005 21:52:37 +0000 (+0000) Subject: * src/pic16/glue.c (pic16_printIvalChar): fixed _constant_ string X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=e4f8761d6870b8f8fecca3574a4e91092cd00c93;p=fw%2Fsdcc * 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 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3774 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 7de1ae31..ea242ced 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-05-26 Raphael Neider + + * 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 * src/pic16/glue.c (pic16_printIvalChar): fixed string diff --git a/src/pic/glue.c b/src/pic/glue.c index 4a36acd7..85d49a3a 100644 --- a/src/pic/glue.c +++ b/src/pic/glue.c @@ -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))); diff --git a/src/pic16/glue.c b/src/pic16/glue.c index c35c0222..7e1d1b76 100644 --- a/src/pic16/glue.c +++ b/src/pic16/glue.c @@ -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;