+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
printIvalChar (sym_link * type, initList * ilist, pBlock *pb, char *s)
{
value *val;
- int remain;
+ int remain, ilen;
if(!pb)
return 0;
{
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)));
#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;