delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/05/13/23:25:49

From: EPA AT datcon DOT co DOT uk (Edward Avis)
Subject: RE: strlen on a NULL
13 May 1998 23:25:49 -0700 :
Message-ID: <c=GB%a=TMAILUK%p=DCNET%l=EXCHANGE2-980513160643Z-9009.cygnus.gnu-win32@smtp.datcon.co.uk>
To: "'gnu-win32 AT cygnus DOT com'" <gnu-win32 AT cygnus DOT com>

>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 AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019