2003-05-30 15:58:25

by Margit Schubert-While

[permalink] [raw]
Subject: drivers/char/sysrq.c

I wonder if there are other places where "&" (or "|") is coded and
"&&" (or "||") is meant (or vice-versa) where the result is NOT semantically
the same :-)
It'll take a good checker to sort that one!

Margit


2003-05-30 20:11:44

by H. Peter Anvin

[permalink] [raw]
Subject: Re: drivers/char/sysrq.c

Followup to: <[email protected]>
By author: "J.A. Magallon" <[email protected]>
In newsgroup: linux.dev.kernel
>
> I see a diff:
> - & is bitwise and you always perform the op
> - && is logical and gcc must shortcut it
>
> I think people use & 'cause they prefer the extra argument calculation
> than the branch for the shortcut (AFAIR...)
>
> or not ?
>

In this case it doesn't matter, since gcc should be able to prove the
right-hand-side is side-effect free.

-hpa
--
<[email protected]> at work, <[email protected]> in private!
"Unix gives you enough rope to shoot yourself in the foot."
Architectures needed: ia64 m68k mips64 ppc ppc64 s390 s390x sh v850 x86-64

2003-05-31 03:05:02

by Valdis Klētnieks

[permalink] [raw]
Subject: Re: drivers/char/sysrq.c

On Fri, 30 May 2003 18:11:49 +0200, [email protected] (Margit Schubert-While) said:
> I wonder if there are other places where "&" (or "|") is coded and
> "&&" (or "||") is meant (or vice-versa) where the result is NOT semantically
> the same :-)
> It'll take a good checker to sort that one!

It shouldn't be hard at all to deal with the form:

(A compare B) op (C compare D)

The scary part would be if the right-hand size has a side-effect - then
the choice of |, & over ||, && would definitely be bug-inducing (or possibly
bug-fixing)?


Attachments:
(No filename) (226.00 B)