Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 13 Mar 2007 16:34:00 +0300
From:      Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To:        Max Laier <max@love2party.net>
Cc:        freebsd-current@freebsd.org
Subject:   Re: Bad gcc -O optimization cause core dump. What to do?
Message-ID:  <20070313133400.GW58523@codelabs.ru>
In-Reply-To: <200703131415.45709.max@love2party.net>
References:  <20070313121106.GA96293@nagual.pp.ru> <20070313123717.GU58523@codelabs.ru> <200703131415.45709.max@love2party.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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



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