From owner-freebsd-current@FreeBSD.ORG Tue Mar 13 13:34:06 2007 Return-Path: X-Original-To: freebsd-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 B014316A402; Tue, 13 Mar 2007 13:34:06 +0000 (UTC) (envelope-from rea-fbsd@codelabs.ru) Received: from pobox.codelabs.ru (pobox.codelabs.ru [144.206.177.45]) by mx1.freebsd.org (Postfix) with ESMTP id 6515913C483; Tue, 13 Mar 2007 13:34:06 +0000 (UTC) (envelope-from rea-fbsd@codelabs.ru) Received: from codelabs.ru (pobox.codelabs.ru [144.206.177.45]) by pobox.codelabs.ru with esmtpsa (TLSv1:AES256-SHA:256) id 1HR78f-000Pkd-0p; Tue, 13 Mar 2007 16:34:05 +0300 Date: Tue, 13 Mar 2007 16:34:00 +0300 From: Eygene Ryabinkin To: Max Laier Message-ID: <20070313133400.GW58523@codelabs.ru> References: <20070313121106.GA96293@nagual.pp.ru> <20070313123717.GU58523@codelabs.ru> <200703131415.45709.max@love2party.net> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline In-Reply-To: <200703131415.45709.max@love2party.net> Sender: rea-fbsd@codelabs.ru X-Spam-Status: No, score=-3.4 required=4.0 tests=ALL_TRUSTED,AWL,BAYES_00 Cc: freebsd-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:34:06 -0000 Slightly off-topic, sorry. > > > Any ideas? Is it right or needs to be fixed? > > > > It is definitely not right, since it produces the bad code. > > And there are no compilation-time checks that can say for > > sure will the argument for the "%s" be NULL: > > This is simply a programming error. Just because the function is called > printf doesn't make it right. It's nice that the libc's printf does all > these neat tricks, but it's also expensive (See the link I posted > earlier). According to the printf(3) manpage: > > s The char * argument is expected to be a pointer to an array of > character type (pointer to a string). Characters from the array > are written up to (but not including) a terminating NUL charac- > ter; if a precision is specified, no more than the number speci- > fied are written. If a precision is given, no null character > need be present; if the precision is not specified, or is greater > than the size of the array, the array must contain a terminating > NUL character. > > And I fail to see how "NULL" is a valid pointer to an array of character > type. This is C after all. In linux there were times (in 2.6 kernel) when mmap was able to return NULL as the handle to a perfectly valid memory area. So NULL is sometimes a good pointer. But it is not our case, so this was off-topic, just for the curiosity. I just wanted to point out that the familiar behaviour of printf() can be restored with the -fno-builtin-printf flag. -- Eygene