public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c/4247: gcc fills variable with random data
@ 2001-09-06 5:06 twiine
0 siblings, 0 replies; 2+ messages in thread
From: twiine @ 2001-09-06 5:06 UTC (permalink / raw)
To: gcc-gnats
>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:
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: c/4247: gcc fills variable with random data
@ 2001-09-09 14:51 aoliva
0 siblings, 0 replies; 2+ messages in thread
From: aoliva @ 2001-09-09 14:51 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, twiine
Synopsis: gcc fills variable with random data
State-Changed-From-To: open->closed
State-Changed-By: aoliva
State-Changed-When: Sun Sep 9 14:51:29 2001
State-Changed-Why:
This is the kind of thing to be expected when you invoke undefined behavior. After c=-1, result[c++] indexes result[-1], and then increments c. -1 is not a valid index into result. From that point on, all bets are off. Perhaps you meant result[++c] ?
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=4247&database=gcc
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-09-09 14:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-06 5:06 c/4247: gcc fills variable with random data twiine
2001-09-09 14:51 aoliva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).