This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c/526: incorrect initialization of array



>Number:         526
>Category:       c
>Synopsis:       incorrect initialization of array
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Sep 12 04:46:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Matthias Meixner
>Release:        gcc version 2.96 20000828 (experimental) + gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
>Organization:
>Environment:
Suse Linux 6.4
>Description:
When initializing an char-array with a string, the array
is not padded with NULL-bytes, if the string is shorter than
the array (e.g. char a[8]="test")
>How-To-Repeat:
/* this program should print "test@@@@" but prints "test@xxx" */
/* compile with "gcc <file>" */

#include <stdio.h>

int main()
{
   char a[8]="test",b[8];
   int i;
   char *x;

   x="xxxx";

   for(i=0;i<8;i++) if(a[i]) putchar(a[i]); else putchar('@');
   putchar('\n');
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]