This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/52769] New: Unspecified designated initializer might not set to zero in some cases
- From: "hudson at osresearch dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 29 Mar 2012 12:41:43 +0000
- Subject: [Bug c/52769] New: Unspecified designated initializer might not set to zero in some cases
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52769
Bug #: 52769
Summary: Unspecified designated initializer might not set to
zero in some cases
Classification: Unclassified
Product: gcc
Version: 4.4.1
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: hudson@osresearch.net
#include <stdio.h>
typedef struct
{
int should_be_zero;
char s[6];
int x;
} foo_t;
int main(void)
{
const foo_t foo = {
.s = "123456",
.x = 2
};
if (foo.should_be_zero != 0)
printf("FAIL: %p val=%d\n", &foo, foo.should_be_zero);
return 0;
}
If s is not fully filled (with room for the terminating nul), the test passes.
If x is not set in the designated initializer, the test passes.
Fails gcc-4.4.1 with both -m32 and -m64:
gcc-4.4 -m64 -std=c99 -O3 initializer-bug.c && ./a.out
FAIL: 0x7fffaf867950 val=-1350141376
gcc-4.4 -m32 -std=c99 -O3 initializer-bug.c && ./a.out
FAIL: 0xffc7df90 val=-144136635
Also fails with 4.3.4, but passes with 4.2.4.