This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c/9029: partially initialized strings are not filled with 0 or C99 stanard misleading
- From: sasha dot mal at excite dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 20 Dec 2002 18:25:03 -0000
- Subject: c/9029: partially initialized strings are not filled with 0 or C99 stanard misleading
- Reply-to: sasha dot mal at excite dot com
>Number: 9029
>Category: c
>Synopsis: partially initialized strings are not filled with 0 or C99 stanard misleading
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Dec 20 10:26:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Alexander Malkis
>Release: gcc version 2.95.4 20011002 (Debian prerelease)
>Organization:
>Environment:
Environment is (env):
PWD=/home/alexmalk/FoPra/test
HOSTDISPLAY=hermite:0.0
FVWM_USERDIR=/home/alexmalk/.fvwm
USER=alexmalk
LANG=C
DISPLAY=:0.0
LOGNAME=alexmalk
SHLVL=1
SSH_AGENT_PID=9280
FVWM_MODULEDIR=/usr/lib/fvwm/2.4.6
SHELL=/usr/local/bin/tcsh
HOME=/home/alexmalk
SSH_AUTH_SOCK=/tmp/ssh-XXaCH3hm/agent.9247
PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/home/alexmalk/pvs
TERM=xterm
WINDOWID=71303184
HOSTTYPE=i386-linux
VENDOR=intel
OSTYPE=linux
MACHTYPE=i386
GROUP=pvs
HOST=hermite
uname -a tells:
Linux hermite 2.2.19 #1 Sat Jun 9 13:04:06 EST 2001 i586 unknown
gcc -v -save-temps test_string.c tells:
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
gcc version 2.95.4 20011002 (Debian prerelease)
/usr/lib/gcc-lib/i386-linux/2.95.4/cpp0 -lang-c -v -D__GNUC__=2 -D__GNUC_MINOR__=95 -D__ELF__ -Dunix -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux -Asystem(posix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ test_string.c test_string.i
GNU CPP version 2.95.4 20011002 (Debian prerelease) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc-lib/i386-linux/2.95.4/include
/usr/include
End of search list.
The following default directories have been omitted from the search path:
/usr/lib/gcc-lib/i386-linux/2.95.4/../../../../include/g++-3
/usr/lib/gcc-lib/i386-linux/2.95.4/../../../../i386-linux/include
End of omitted list.
/usr/lib/gcc-lib/i386-linux/2.95.4/cc1 test_string.i -quiet -dumpbase test_string.c -version -o test_string.s
GNU C version 2.95.4 20011002 (Debian prerelease) (i386-linux) compiled by GNU C version 2.95.4 20011002 (Debian prerelease).
test_string.c: In function `main':
test_string.c:1: warning: return type of `main' is not `int'
as -V -Qy -o test_string.o test_string.s
GNU assembler version 2.12.90.0.1 (i386-linux) using BFD version 2.12.90.0.1 20020307 Debian/GNU Linux
/usr/lib/gcc-lib/i386-linux/2.95.4/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/i386-linux/2.95.4/crtbegin.o -L/usr/lib/gcc-lib/i386-linux/2.95.4 test_string.o -lgcc -lc -lgcc /usr/lib/gcc-lib/i386-linux/2.95.4/crtend.o /usr/lib/crtn.o
>Description:
/* The last element of z should be initialized with 0, but it is filled with 37.
See C99 standard, 6.7.8, paragraph 21: partially initialized strings should be filled up with 0. The code follows
*/
# 1 "test_string.c"
void main(void) {
char w[4]={'a','b'};
char z[4]="ab";
printf("%d %d %d %d\n%d %d %d %d\n",(int)(w[0]),(int)(w[1]),(int)(w[2]),(int)(w[3]),(int)(z[0]),(int)(z[1]),(int)(z[2]),(int)(z[3]));
}
>How-To-Repeat:
Compile the file and run it. Two lines, each of 4 numbers are produced. Each line should have exactly 2 tailing zeros, but the second doesn't.
>Fix:
Correct the compiler.
>Release-Note:
>Audit-Trail:
>Unformatted: