c/526: incorrect initialization of array

meixner@rbg.informatik.tu-darmstadt.de meixner@rbg.informatik.tu-darmstadt.de
Tue Sep 12 04:46:00 GMT 2000


>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:


More information about the Gcc-prs mailing list