Re: [SystemSafety] OpenSSL Bug

From: David Haworth < >
Date: Wed, 16 Apr 2014 13:08:33 +0200


Hi,

I was trying to keep out of this, but I'm starting to get sick of this particular example.

    if ((a = check()) = SUCCESS) { ... }

fails to compile because (a = check()) is not an lvalue.

So

    if ((a = check()) == SUCCESS) { ... }

is a perfectly safe construct. Unless, of course, what you really intended to write was

    if ((a == check()) == SUCCESS) { ... }

in which case you should take yourself out and shoot yourself for comparing an effectively boolean result with a specific numerical value.

_at_xxxxxx be the most recent person to quote this nonsensical example.

Dave

On 2014-04-16 10:17:41 +0000, Steve Tockey wrote:
>
> I'm not arguing for or against C, but I have seen coding standards that
> prohibit:
>
> if ((a = check()) == SUCCESS) { ... }
>
>
>
> They require instead:
>
> if ( SUCCESS == (a = check()) ) { ... }
>
>
>
> Simply moving the constant to the left side makes it an ill-formed
> expression if the "==" is accidentally switched for "=":
>
> if ( SUCCESS = (a = check()) ) { ... }
>
>
>
>
> -- steve

-- 
David Haworth B.Sc.(Hons.), OS Kernel Developer    david.haworth_at_xxxxxx
Tel: +49 9131 7701-6154     Fax: -6333                  Keys: keyserver.pgp.com
Elektrobit Automotive GmbH           Am Wolfsmantel 46, 91058 Erlangen, Germany
Geschäftsführer: Alexander Kocher, Gregor Zink       Amtsgericht Fürth HRB 4886



_______________________________________________ The System Safety Mailing List systemsafety_at_xxxxxx
Received on Wed Apr 16 2014 - 13:09:01 CEST

This archive was generated by hypermail 2.3.0 : Sat Feb 23 2019 - 01:17:07 CET