Bug#392880: gcc-4.1: off-by-one error for string initialiser warnings
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
Reply to: