This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c/4247: gcc fills variable with random data
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c/4247: gcc fills variable with random data
- From: twiine at web dot de
- Date: 6 Sep 2001 11:58:47 -0000
- Reply-To: twiine at web dot de
>Number: 4247
>Category: c
>Synopsis: gcc fills variable with random data
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Thu Sep 06 05:06:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: twiine@web.de
>Release: gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
SuSE Linux 7.0 (Kernel 2.2.16)
>Description:
The expression result[c++] = files; sets the c variable to a random value. (Seems to be c = files + 1). The problem only appears when c is initialized with -1.
The error also occurs with the latest snapshot of gcc.
Command line: gcc -Wall -o test test.c
>How-To-Repeat:
int main(int argc, char *argv[])
{
char *files, *result[5];
int c=-1;
result[c++] = files;
return 0;
}
>Fix:
The expression
c++;
result[c] = files;
works fine or if you enable optimzing.
>Release-Note:
>Audit-Trail:
>Unformatted: