From owner-freebsd-current@FreeBSD.ORG Tue Mar 13 13:55:48 2007 Return-Path: X-Original-To: current@freebsd.org Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 20AF316A507; Tue, 13 Mar 2007 13:55:48 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (tim.des.no [194.63.250.121]) by mx1.freebsd.org (Postfix) with ESMTP id B649813C4BD; Tue, 13 Mar 2007 13:55:34 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (localhost [127.0.0.1]) by spam.des.no (Postfix) with ESMTP id 87118208C; Tue, 13 Mar 2007 14:23:53 +0100 (CET) X-Spam-Tests: AWL X-Spam-Learn: disabled X-Spam-Score: 0.0/3.0 X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on tim.des.no Received: from dwp.des.no (des.no [80.203.243.180]) by tim.des.no (Postfix) with ESMTP id 6CA8E2089; Tue, 13 Mar 2007 14:23:53 +0100 (CET) Received: by dwp.des.no (Postfix, from userid 1001) id 55701B88E; Tue, 13 Mar 2007 14:23:53 +0100 (CET) From: des@des.no (Dag-Erling =?iso-8859-1?Q?Sm=F8rgrav?=) To: Andrey Chernov References: <20070313121106.GA96293@nagual.pp.ru> Date: Tue, 13 Mar 2007 14:23:53 +0100 In-Reply-To: <20070313121106.GA96293@nagual.pp.ru> (Andrey Chernov's message of "Tue, 13 Mar 2007 15:11:07 +0300") Message-ID: <86veh56zva.fsf@dwp.des.no> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.3 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Cc: current@freebsd.org Subject: Re: Bad gcc -O optimization cause core dump. What to do? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Mar 2007 13:55:48 -0000 Andrey Chernov writes: > Copy the segment below to the file a.c > ---------------------- cut me here --------------------- > #include > > 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