mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Horst von Brand <vonbrand@inf.utfsm.cl>
To: "Jean Delvare" <khali@linux-fr.org>
Cc: vonbrand@inf.utfsm.cl, "Andrew Morton" <akpm@osdl.org>,
	"Adrian Bunk" <bunk@stusta.de>,
	"LKML" <linux-kernel@vger.kernel.org>
Subject: Re: Do not misuse Coverity please
Date: Wed, 30 Mar 2005 13:09:32 -0400	[thread overview]
Message-ID: <200503301709.j2UH9WsA008556@laptop11.inf.utfsm.cl> (raw)
In-Reply-To: Message from "Jean Delvare" <khali@linux-fr.org>  of "Wed, 30 Mar 2005 09:53:03 +0200." <OofSaT76.1112169183.7124470.khali@localhost>

"Jean Delvare" <khali@linux-fr.org> said:
> > > > No, there is a third case: the pointer can be NULL, but the compiler
> > > > happened to move the dereference down to after the check.

> > > Wow. Great point. I completely missed that possibility. In fact I didn't
> > > know that the compiler could possibly alter the order of the
> > > instructions. For one thing, I thought it was simply not allowed to. For
> > > another, I didn't know that it had been made so aware that it could
> > > actually figure out how to do this kind of things. What a mess. Let's
> > > just hope that the gcc folks know their business :)

> > The compiler is most definitely /not/ allowed to change the results the
> > code gives.

> I think that Andrew's point was that the compiler could change the order
> of the instructions *when this doesn't change the result*, not just in
> the general case, of course. In our example, The instructions:
> 
>     v = p->field;
>     if (!p) return;
> 
> can be seen as equivalent to
> 
>     if (!p) return;
>     v = p->field;

They are not. If p == NULL, the first gives an exception (SIGSEGV), the
second one doesn't. Just as you can't "optimize" by switching:

    x = b / a;   
    if (a == 0) return;
-- 
Dr. Horst H. von Brand                   User #22616 counter.li.org
Departamento de Informatica                     Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria              +56 32 654239
Casilla 110-V, Valparaiso, Chile                Fax:  +56 32 797513

  reply	other threads:[~2005-03-30 17:11 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-27 20:50 [2.6 patch] sound/oss/cs46xx.c: fix a check after use Adrian Bunk
2005-03-27 21:21 ` Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use) Jean Delvare
2005-03-27 21:43   ` Adrian Bunk
2005-03-27 22:34     ` Jean Delvare
2005-03-27 22:45       ` Russell King
2005-03-28 12:54       ` Matthias-Christian Ott
2005-03-28 23:57     ` L. A. Walsh
2005-03-29  6:05       ` Daniel Barkalow
2005-03-29  6:23   ` Andrew Morton
2005-03-29 10:46     ` Jean Delvare
2005-03-29 14:12       ` Chris Friesen
2005-03-30  1:25       ` Horst von Brand
2005-03-30  7:53         ` Do not misuse Coverity please Jean Delvare
2005-03-30 17:09           ` Horst von Brand [this message]
2005-04-11 20:23             ` Pavel Machek
2005-03-30 18:29           ` Shankar Unni
2005-03-30 18:55             ` Olivier Galibert
2005-03-31  2:01               ` Patrick McFarland
2005-03-30 19:14             ` Paulo Marques
2005-03-30 23:11               ` Big GCC bug!!! [Was: Re: Do not misuse Coverity please] Kyle Moffett
2005-03-30 23:38                 ` Not a GCC bug (was Re: Big GCC bug!!! [Was: Re: Do not misuse Coverity please]) Jakub Jelinek
2005-03-31  0:58                   ` Kyle Moffett
2005-03-31  1:12                     ` Nick Piggin
2005-03-31  1:27                       ` Kyle Moffett
2005-03-29 14:22     ` Do not misuse Coverity please (Was: sound/oss/cs46xx.c: fix a check after use) Daniel Jacobowitz
2005-03-29 22:37       ` Kyle Moffett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200503301709.j2UH9WsA008556@laptop11.inf.utfsm.cl \
    --to=vonbrand@inf.utfsm.cl \
    --cc=akpm@osdl.org \
    --cc=bunk@stusta.de \
    --cc=khali@linux-fr.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®