* src/SDCCast.c (createIvalCharPtr),
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 18 Dec 2003 21:23:36 +0000 (21:23 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 18 Dec 2003 21:23:36 +0000 (21:23 +0000)
* src/SDCCglue.c (printChar): fixed bug #862241 (an error in my fix for
bug #753752)
* support/regression/tests/nullstring.c: tests for these two bugs

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

ChangeLog
src/SDCCast.c
src/SDCCglue.c
support/regression/tests/nullstring.c [new file with mode: 0644]

index 38806fd236cc731c124a97ea23a890c36630cea1..a6e261eb259c608634a168656f7840dbf5c1d9b8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2003-12-18 Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
+       * src/SDCCast.c (createIvalCharPtr),
+       * src/SDCCglue.c (printChar): fixed bug #862241 (an error in my fix for
+       bug #753752)
+       * support/regression/tests/nullstring.c: tests for these two bugs
+
 2003-12-18 Erik Petrich <epetrich@ivorytower.norman.ok.us>
 
        * support/Util/SDCCerr.h,
index 45c971d1ecec8541acdec5e1726dbaf0f5a9f8ee..098cedbadc3c59c0d7a53dc98f6cd8a951e59676 100644 (file)
@@ -994,6 +994,15 @@ createIvalCharPtr (ast * sym, sym_link * type, ast * iexpr)
       char *s = SPEC_CVAL (iexpr->etype).v_char;
       int i = 0;
       int size = getSize (iexpr->ftype);
+      int symsize = getSize (type);
+      
+      if (size>symsize)
+        {
+         if (size>(symsize+1))
+           werrorfl (iexpr->filename, iexpr->lineno, W_EXCESS_INITIALIZERS,
+                     "string", sym->opval.val->sym->name);
+         size = symsize;
+       }
 
       for (i=0;i<size;i++)
        {
index fde4be676a54ff4a3ffe55998217b2d2c0e7e716..47584b541fdcdbad0a014a3fdabfcaef069159d7 100644 (file)
@@ -546,6 +546,11 @@ printChar (FILE * ofile, char *s, int plen)
       else
        len = 0;
     }
+  while (pplen < plen)
+    {
+      tfprintf (ofile, "\t!db !constbyte\n", 0);
+      pplen++;
+    }
 }
 
 /*-----------------------------------------------------------------*/
diff --git a/support/regression/tests/nullstring.c b/support/regression/tests/nullstring.c
new file mode 100644 (file)
index 0000000..51313c8
--- /dev/null
@@ -0,0 +1,42 @@
+/** Null character in string tests.
+
+     storage: data, xdata, code,
+*/
+#include <testfwk.h>
+
+#if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80)
+# define data
+# define xdata
+# define code
+#endif
+
+{storage} char string1[] = "";
+{storage} char string2[] = "a\0b\0c";
+{storage} char string3[5] = "a\0b\0c";
+
+void
+testStringArray(void)
+{
+  /* Make sure the strings are the correct size */
+  /* and have the terminating null character */
+  ASSERT(sizeof(string1)==1);
+  ASSERT(sizeof(string2)==6);
+  ASSERT(sizeof(string3)==5);
+  ASSERT(string1[0]==0);
+  ASSERT(string2[5]==0);
+  
+  ASSERT(string2[0]=='a');
+  ASSERT(string2[2]=='b');
+  ASSERT(string2[4]=='c');  
+  
+}
+
+void
+testStringConst(void)
+{
+  char * constStr1 = "";
+  char * constStr2 = "a\0b\0c";
+
+  ASSERT (constStr1[0]==0);
+  ASSERT (constStr2[5]==0);
+}