strlen on NULL, final test
Ron G. Minnich
rminnich@sarnoff.com
Wed May 13 15:43:00 GMT 1998
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".
More information about the Cygwin
mailing list