strdup(NULL) supposed to create SIGSEGV?
Constantine A. Murenin
mureninc at gmail.com
Wed Apr 23 07:38:35 UTC 2008
On 23/04/2008, Garrett Cooper <yanefbsd at 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.
More information about the freebsd-hackers
mailing list