From: cuz Date: Sat, 19 Jul 2003 09:12:38 +0000 (+0000) Subject: Bug: Char arrays with a specified size could not be initialized with literal X-Git-Tag: V2.12.0~1490 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=cc9263d413c8096429c4d0b83a16079c37b290f5;p=cc65 Bug: Char arrays with a specified size could not be initialized with literal 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 --- diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 044ec9870..73f7e27ea 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -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 */