Subject: RE: strlen on a NULL
From: [email-masked] (Edward Avis)

13 May 1998 23:25:49 -0700
Message-ID: <c=GB%a=TMAILUK%p=DCNET%l=[email-masked]>
To: "[email-masked]'" <[email-masked]>

>nonsense. if strlen() doesn't crash when given a null pointer, the only
>reason is that the implementation must contain a test for the null
>pointer. this is atypical. strlen(NULL) normally crashes on unix. unix
>core files may start at address zero, but zero is an illegal address.
>this is deliberate. using null pointers is so common an error in c
>programming, that the null address was deemed to always be invalid.
>remember that c and unix were invented together.

There is a difference between a null pointer and zero as an address.  On
some machines, the null pointer is actually a non-zero number, though
still represented in C as "0".  Read the C FAQ for more details.

Whatever the correct behaviour is, it's obvious that different systems
do different things, and hence strlen(0) is worth avoiding.  Certainly
this isn't a bug in cygwin.

--
Ed Avis <http://members.tripod.com/~mave>
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".