Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!ncar!gatech!amdcad!news
From: news@amdcad.AMD.COM (Network News)
Newsgroups: comp.sources.bugs
Subject: Re: Patch #2 to Pcomm v1.1
Message-ID: <22983@amdcad.AMD.COM>
Date: 21 Sep 88 20:37:02 GMT
References: <13900004@osiris.cso.uiuc.edu> <416@quintus.UUCP> <7782@bcsaic.UUCP>
Reply-To: tim@crackle.amd.com (Tim Olson)
Organization: Advanced Micro Devices, Inc., Sunnyvale CA
Lines: 33
Summary:
Expires:
Sender:
Followup-To:

In article <7782@bcsaic.UUCP> paula@bcsaic.UUCP (Paul Allen) writes:
| In article <416@quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes:
| >In article <13900004@osiris.cso.uiuc.edu> hood@osiris.cso.uiuc.edu writes:
| >>This patch will fix the problem that some people are having with 
| >>seqmentation faults (although I'm not convinced the problem isn't
| >>in their compiler).
| >
| >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.

No.  Check your reference again: the operators '&&' '||' ',' all
guarantee left-to-right evaluation of the operands.  This type of
expression is the main reason why && and || are short-circuit
evaluators.  The fix is correctly written:

	if (lock_path != NULL && *lock_path != NULL)

or, if you prefer:

	if (lock_path && *lock_path)


	-- Tim Olson
	Advanced Micro Devices
	(tim@crackle.amd.com)