Re: [xml] A long URL causes SEGV



On Mon, Feb 09, 2004 at 03:22:34PM +0100, Igor Zlatkovic wrote:
That however doesn't happen. The C compiler, when doing a (...) && (...) 
&& (...), won't evaluate further parentheses after it encounters the 
first one that evaluates to false. In our example, test for cur[1] is 
false and an access to cur[2] doesn't happen.

Question: Who can guarantee that all compilers really behave this way? 
Is there anything in the C spec that forces the compiler to evaluate 
these parentheses in exactly this manner?

  The C spec itself.
  There is an awful lot of code relying on the order of such compound
test, like for example
   if ((p != NULL) && (*p != 0))
you have the right to expect that if p is NULL the dereference will not occur.
It's the same for the test you pointed out, and in a lot of places in libxml2
code.

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



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