Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 31 Mar 2004 12:20:35 +0200
From:      "Poul-Henning Kamp" <phk@phk.freebsd.dk>
To:        Rene Ladan <r.c.ladan@student.tue.nl>
Cc:        freebsd-current@freebsd.org
Subject:   Re: system's gcc bug? 
Message-ID:  <9532.1080728435@critter.freebsd.dk>
In-Reply-To: Your message of "Wed, 31 Mar 2004 12:18:34 %2B0200." <20040331101834.GA21652@dyn-099164.nbw.tue.nl> 

next in thread | previous in thread | raw e-mail | index | archive | help
In message <20040331101834.GA21652@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@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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9532.1080728435>