Date: Wed, 23 Apr 2008 03:13:14 -0400 From: "Constantine A. Murenin" <mureninc@gmail.com> To: "Garrett Cooper" <yanefbsd@gmail.com> Cc: hackers@freebsd.org Subject: Re: strdup(NULL) supposed to create SIGSEGV? Message-ID: <f34ca13c0804230013o255aba1ftd5460a83ff508f38@mail.gmail.com> In-Reply-To: <7d6fde3d0804222240j6b42b77yd86d8accb5a959fa@mail.gmail.com> References: <7d6fde3d0804222240j6b42b77yd86d8accb5a959fa@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?f34ca13c0804230013o255aba1ftd5460a83ff508f38>