Subject: strlen on NULL, final test
From: [email-masked] (Ron G. Minnich)

13 May 1998 23:25:52 -0700
Message-ID: <Pine.SUN.3.91.980513103235.8402A-100000.cygnus.gnu-win32@terra>
References: <[email-masked]>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
To: [email-masked]

to finish this off once and for all, someone raised the question of a
strlen that might test the argument to see if it's equal to 0, and then
return 0. 

First, the empty string and the null string are different, and length of 
a null string has no meaning. 
Second, if you have null pointers, as others say, fix your code. 

But, even though it's a bad idea, who knows: someone might do it. 

bash$ cat test.c
main()
{
  (void) strlen((char *) 0);
}

bash$ cc test.c
bash$ ./a.out
Segmentation fault (core dumped)
bash$ 

Again: linux, freebsd, sunos, solaris.

So I have not yet seen the strlen that works with strlen((char *)0);

ron

Ron Minnich                |Java: an operating-system-independent, 
[email-masked]       |architecture-independent programming language
(609)-734-3120             |for Windows/95 and Windows/NT on the Pentium
ftp://ftp.sarnoff.com/pub/mnfs/www/docs/cluster.html 

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".