Date: Tue, 13 Mar 2007 14:23:53 +0100 From: des@des.no (Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?=) To: Andrey Chernov <ache@freebsd.org> Cc: current@freebsd.org Subject: Re: Bad gcc -O optimization cause core dump. What to do? Message-ID: <86veh56zva.fsf@dwp.des.no> In-Reply-To: <20070313121106.GA96293@nagual.pp.ru> (Andrey Chernov's message of "Tue, 13 Mar 2007 15:11:07 %2B0300") References: <20070313121106.GA96293@nagual.pp.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
Andrey Chernov <ache@freebsd.org> writes:
> Copy the segment below to the file a.c
> ---------------------- cut me here ---------------------
> #include <stdio.h>
>
> main() {
> printf("%s\n", NULL);
> }
> ---------------------- cut me here ---------------------
> [...]
> It calls "puts(NULL)" with core dump.
> It means "printf("%s\n", NULL)" is overoptimized.
> BTW, things like "printf("1%s\n", NULL)" are not overoptimized.
> Any ideas? Is it right or needs to be fixed?
The behaviour of printf("%s\n", NULL) is undefined. GCC is perfectly
within its rights to translate it into something that dumps core (or
causes your disk to crash, your monitor to explode, your dog to die of
a venereal disease, and demons to fly out of your nose)
Specifically, the C standard (=A77.19.6.1) requires the argument that
corresponds to %s to be a pointer to "the initial element of an array
of character type", which NULL is not.
DES
--=20
Dag-Erling Sm=F8rgrav - des@des.no
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86veh56zva.fsf>
