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

From: rminnich AT sarnoff DOT com (Ron G. Minnich)
Subject: strlen on NULL, final test
13 May 1998 23:25:52 -0700 :
Message-ID: <Pine.SUN.3.91.980513103235.8402A-100000.cygnus.gnu-win32@terra>
References: <6tksqweppfB AT mike DOT franken DOT de>
Mime-Version: 1.0
To: gnu-win32 AT cygnus DOT com

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, 
rminnich AT sarnoff DOT com       |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
"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