This is the mail archive of the
cygwin@sourceware.cygnus.com
mailing list for the Cygwin project.
RE: strlen on a NULL
- To: "'gnu-win32 at cygnus dot com'" <gnu-win32 at cygnus dot com>
- Subject: RE: strlen on a NULL
- From: Edward Avis <EPA at datcon dot co dot uk>
- Date: Wed, 13 May 1998 17:06:43 +0100
>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
"gnu-win32-request@cygnus.com" with one line of text: "help".