system's gcc bug?

Poul-Henning Kamp phk at phk.freebsd.dk
Wed Mar 31 02:20:41 PST 2004


In message <20040331101834.GA21652 at dyn-099164.nbw.tue.nl>, Rene Ladan writes:
>
>--rwEMma7ioTxnRzrJ
>Content-Type: text/plain; charset=us-ascii
>Content-Disposition: inline
>
>Hi,
>
>I'm getting runtime errors when executing the following program and
>declaring one of the arrays:
>
>----------------
>
>#include <stdio.h>
>
>int main(void) {
>/*	int a[4] = { 0, 1, 2, 3 };   enable this line to get a buserror */
>	int *i;
>/*	int b[4] = { 0, 1, 2, 3 };   enable this line to get a segfault */
>	for (*i = 0; *i < 4; (*i)++)
>		printf("%p %i\n", i, *i);
>	return(0);
> }

You have allocated no storage backing for *i, so your for loop writes
the integers 0...3 to a random place in memory.

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.


More information about the freebsd-current mailing list