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

From: Ricardo Nabinger Sanchez <rnsanchez_at_wait4.org>
Date: Tue, 13 Mar 2007 13:21:58 -0300
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_at_{gmail.com,wait4.org}>
Powered by FreeBSD

  "Left to themselves, things tend to go from bad to worse."
Received on Tue Mar 13 2007 - 15:22:04 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:06 UTC