c/4247: gcc fills variable with random data

twiine@web.de twiine@web.de
Thu Sep 6 05:06:00 GMT 2001

>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
>Originator:     twiine@web.de
>Release:        gcc version 2.95.2 19991024 (release)
SuSE Linux 7.0 (Kernel 2.2.16)
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
int main(int argc, char *argv[])
  char *files, *result[5];
  int c=-1;

  result[c++] = files;
  return 0;
The expression 
    result[c] = files;
works fine or if you enable optimzing.

More information about the Gcc-bugs mailing list