Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!cornell!uw-beaver!teknowledge-vaxc!mkhaw From: mkhaw@teknowledge-vaxc.ARPA (Mike Khaw) Newsgroups: comp.sources.bugs Subject: Re: Patch #2 to Pcomm v1.1 Message-ID: <25069@teknowledge-vaxc.ARPA> Date: 21 Sep 88 17:53:44 GMT References: <7782@bcsaic.UUCP> Organization: Teknowledge, Inc., Palo Alto CA Lines: 27 In article <7782@bcsaic.UUCP> paula@bcsaic.UUCP (Paul Allen) writes: >> >>>! if (*lock_path != NULL && lock_path != NULL) { >> >>This only tests whether lock_path is legal *after* trying to use it! > > I've now seen a couple postings about this bug, but nobody has got it > right yet! What has been missed is that C makes no guarantee about the <-- > order of expression evaluation. The only safe way to perform this test <-- > is using two nested if statements. <-- from page 19 of K&R (1978 ed.) Expressions connected by && or || are evaluated left to right ^^^^^^^^^^^^^ furthermore, "!=" has higher precedence than "&&" so if (lock_path != NULL && *lock_path != NULL) is correct. Mike Khaw -- internet: mkhaw@teknowledge.arpa uucp: {uunet|sun|ucbvax|decwrl|uw-beaver}!mkhaw%teknowledge.arpa hardcopy: Teknowledge Inc, 1850 Embarcadero Rd, POB 10119, Palo Alto, CA 94303