Re: [PATCH] Fix test for CTC devices from yesterday.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Nov 04, 2010 at 01:34:29PM +0100, Radek Vykydal wrote:

> my suggestion
> if ( type != 1 && !(!strncmp(ent->d_name, "ctc", 3) && type == 256) )
> gives:
> A: FAIL
> B: PASS
> C: PASS

I agree with Radek here. This is how I examine these kinds of problems:


TRUE: if type != 1 and type != 256 

TRUE: if type == 256 but name isn't ctc 

if ((type != 1) && !((type == 256) && !strncmp(name, "ctc", 3)))
       #1                #2              #3

type, name   1  !(2&&3)  2  3    Result
1     bob    F   T       F  F      F    skip continue
2     sam    T   T       F  F      T    continue
256   sam    T   T       T  F      T    continue
256   ctc    T   F       T  T      F    skip continue

I like putting the type check first because that will short-circuit the && 
preventing needless calls to strncmp. And some may say I use () excessively, 
but it prevents confusion when evaluating long expressions.


-- 
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)

Attachment: pgpCJIatNPgUk.pgp
Description: PGP signature

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux