Bad gcc -O optimization cause core dump. What to do?

Ricardo Nabinger Sanchez rnsanchez at wait4.org
Tue Mar 13 16:22:05 UTC 2007


On Tue, 13 Mar 2007 15:06:32 +0100
Maxime Henrion <mux at FreeBSD.org> wrote:

> > Given that this is not what the user asked (replacing printf with puts), I
> > consider this a bug.  GCC made its assumption, and it was incorrect--it's
> > not user's fault.
> 
> GCC can do whatever it wants here, even printing "foobar42", because the
> C standard says that passing a NULL pointer to a %s format will yield
> undefined behaviour.  It *is* user's fault to have passed NULL to
> printf() in the first place.
> 
> So, while we could argue that GCC's behaviour here is useless, annoying,
> etc, this just can't be called a bug in GCC.  As a side note, these
> "optimizations" are in place since a *long* time now.

... Considered until now.  :)

Honestly, I wasn't aware of these specific issues (detail in the C standard +
gcc builtin printf optimization), and that's surely _my_ fault, not gcc's.

Sorry for the (useless) noise.  Thank you (and DES) for pointing this out.

-- 
Ricardo Nabinger Sanchez     <rnsanchez@{gmail.com,wait4.org}>
Powered by FreeBSD

  "Left to themselves, things tend to go from bad to worse."


More information about the freebsd-current mailing list