Re: strdup(NULL) supposed to create SIGSEGV?
On 23/04/2008, Garrett Cooper <yanefbsd@gmail.com> wrote:
> Hi all,
> I made an oops in a program, which uncovered "feature" in strdup(2)
> that I wasn't aware of before. So I was wondering, is strdup(pointer = NULL)
> supposed to segfault should this just return NULL and set errno?
> Good news is that Linux does the same thing (yay?), so at least FreeBSD
> isn't alone..
strdup(3) duplicates a string, and NULL is obviously not a string.
Or would you expect strlen(NULL) to return 0 and set errno, too? But
then you have to redesign most, if not all, libc string functions
(http://cvsweb.freebsd.org/src/lib/libc/string/), breaking the
expected behaviour of many existing applications and promoting
unportable code.
C.
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
討論串 (同標題文章)
完整討論串 (本文為第 4 之 25 篇):