[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#392880: marked as done ([PR29468] off-by-one error for string initialiser warnings)



Your message dated Sat, 14 Oct 2006 15:13:22 +0100
with message-id <20061014141322.GA23656@burmah.seehuhn.de>
and subject line Bug#392880: gcc-4.1: off-by-one error for string initialiser warnings
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--- Begin Message ---
Package: gcc-4.1
Version: 4.1.1-16
Severity: normal

Hello,

one very useful feature of gcc is, that it warns you when you produce
unterminated strings by using too long initialisers.  Unfortunately
the warning only kicks in, if the initialiser is at least two bytes
longer than the string buffer.  This is illustrated by the following
example:

    voss@burmah [~] cat t.c
    #include <stdio.h>
    char a[]="a";
    char string1[2] = "";
    char b[]="b";
    char string2[2] = "1";
    char c[]="c";
    char string3[2] = "12";
    char d[]="d";
    char string4[2] = "123";
    char e[]="e";
    int
    main()
    {
      puts(string1);
      puts(string2);
      puts(string3);
      puts(string4);
      return 0;
    }
    voss@burmah [~] gcc -Wall t.c
    t.c:9: warning: initializer-string for array of chars is too long
    voss@burmah [~] ./a.out

    1
    12d
    12e

Here 'string3' and 'string4' are unterminated, as can be seen from the
program output at the end.  But only the initialiser for 'string4'
gives a warning.  It would be nice if there would also be a warning
for the case when the initialiser is just one byte too long (i.e. for
'string3' in my example).

I hope this helps,
Jochen

-- System Information:
Debian Release: testing/unstable
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.17.13
Locale: LANG=en_GB.iso885915, LC_CTYPE=en_GB.iso885915 (charmap=ISO-8859-15)

Versions of packages gcc-4.1 depends on:
ii  binutils                     2.17-3      The GNU assembler, linker and bina
ii  cpp-4.1                      4.1.1-16    The GNU C preprocessor
ii  gcc-4.1-base                 4.1.1-16    The GNU Compiler Collection (base 
ii  libc6                        2.3.6.ds1-6 GNU C Library: Shared libraries
ii  libgcc1                      1:4.1.1-16  GCC support library
ii  libssp0                      4.1.1-16    GCC stack smashing protection libr

Versions of packages gcc-4.1 recommends:
ii  libc6-dev                    2.3.6.ds1-6 GNU C Library: Development Librari
ii  libmudflap0-dev              4.1.1-16    GCC mudflap support libraries (dev

-- no debconf information


--- End Message ---
--- Begin Message ---
Hi Philip,

On Sat, Oct 14, 2006 at 03:03:18PM +0100, Philip Martin wrote:
> Jochen Voss <voss@debian.org> writes:
> 
> >     char string3[2] = "12";
> >     char d[]="d";
> >     char string4[2] = "123";
> >     char e[]="e";
> 
> > Here 'string3' and 'string4' are unterminated, as can be seen from the
> > program output at the end.  But only the initialiser for 'string4'
> > gives a warning.  It would be nice if there would also be a warning
> > for the case when the initialiser is just one byte too long (i.e. for
> > 'string3' in my example).
> 
> The string3 initialiser is not too long, section 6.7.8/15 of the ISO C
> standard states:
> 
>    "Successive characters of the character literal (including the
>     terminating null character if there is room or if the array is of
>     unknown size) initialize the elements of the array"
> 
> So string3 is correctly initialized with the two bytes '1' and '2' and
> the terminating null is discarded.

Yes, sure, the behaviour of gcc to create unterminated strings for
string3 and string4 is certainly correct.  I just found it confusing
that string4 gave a warning while string3 did not.

But I understand now (from Falk's explanation) that this is a feature
and not bug, so I'm closing the report.  My apologies for the noise.

All the best,
Jochen
-- 
http://seehuhn.de/

Attachment: signature.asc
Description: Digital signature


--- End Message ---

Reply to: