Patch #2 to Pcomm v1.1

Danny danny at itm.UUCP
Thu Sep 22 22:42:16 AEST 1988


In article <7782 at bcsaic.UUCP> paula at bcsaic.UUCP (Paul Allen) writes:
~In article <416 at quintus.UUCP> ok at quintus.UUCP (Richard A. O'Keefe) writes:
~>
~>It isn't.  It's the famous *NULL bug.
~>
~>>! 	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.

    Sorry, wrong.  See page 190, section 7.11: "Logical AND operator"
in K&R.  "Unlike &, && guarantees left-to-right evaluation; moreover
the second operand is not evaluated if the first operand is 0."

    The above line should read:
     	if (lock_path != NULL && *lock_path != NULL) {
            -or-
      if (lock_path && *lock_path) {
    
    Left to right evaluation of logical connectives and short-circuiting
is one of the nicest aspects of C!  If your compiler doesn't do it, it's
not a C compiler.  Complain loudly to your vendor.

                                    Danny
-- 
				Daniel S. Cox
				(seismo!gatech!itm!danny)



More information about the Comp.sources.bugs mailing list