]> git.sur5r.net Git - cc65/commitdiff
Bug: Char arrays with a specified size could not be initialized with literal
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 19 Jul 2003 09:12:38 +0000 (09:12 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 19 Jul 2003 09:12:38 +0000 (09:12 +0000)
strings that had the same length as the char array (in this case the zero
terminator must be omitted by the compiler).

git-svn-id: svn://svn.cc65.org/cc65/trunk@2230 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/cc65/declare.c

index 044ec98704e20768126d588ec3dc52d7337a7100..73f7e27ead1c43fbc2483d3619381e0bb7a8a077 100644 (file)
@@ -1155,6 +1155,18 @@ static unsigned ParseArrayInit (type* T, int AllowFlexibleMembers)
 
         /* Translate into target charset */
         TranslateLiteralPool (CurTok.IVal);
+
+        /* If the array is one too small for the string literal, omit the
+         * trailing zero.
+         */
+        if (ElementCount != UNSPECIFIED &&
+            ElementCount != FLEXIBLE    &&
+            Count        == ElementCount + 1) {
+            /* Omit the trailing zero */
+            --Count;
+        }
+
+        /* Output the data */
         g_defbytes (Str, Count);
 
         /* Remove string from pool */