This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: strlen on a NULL


>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".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]