This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

[Bug c/13896] New: Initializer string warning not printed if implied NULL-terminator out of bounds


If the following string array is declared,

char a[][3] = {{"Hello"}, {"Hi"}};

the following warning will be printed when the source file is compiled:
warning: initializer-string for array of chars is too long
warning: (near initialization for `a[0]')

If the array is changed to this,

char a[][3] = {{"Hel"}, {"Hi"}};

no warning is printed.  But of course a[1][0] ('H') overwrites the NULL-
terminator at a[0][3], so a[0] prints as "HelHi".  A warning should be printed 
for this.

-- 
           Summary: Initializer string warning not printed if implied NULL-
                    terminator out of bounds
           Product: gcc
           Version: 3.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rhajdaj at yahoo dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13896


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