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]

strlen on NULL, final test


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@sarnoff.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@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]