Date: Wed, 23 Apr 2008 21:31:03 +1000 From: Greg Black <freebsd-nospam@yaxom.com> To: Simun Mikecin <numisemis@yahoo.com> Cc: hackers@freebsd.org Subject: Re: strdup(NULL) supposed to create SIGSEGV? Message-ID: <nospam-1208950264.18834@joker.yaxom.com> In-Reply-To: <251738.1147.qm@web36602.mail.mud.yahoo.com> References: <251738.1147.qm@web36602.mail.mud.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2008-04-23, Simun Mikecin wrote: > According to Open Group strdup should return NULL and set errno. Look at: > http://www.opengroup.org/onlinepubs/009695399/functions/strdup.html If you're going to quote documents to support your ideas, it's probably better to read them first. That document gives only lack of memory as a reason for failure. It does not state clearly, but clearly requires, correct behaviour from the caller who is required to provide a string argument. NULL is not a string, so the behaviour of the function is undefined. Basic C programming requires people not to step into the wilderness of undefined behaviour. > There is no valid argument for doing segfault instead of above behavior. If you can find an alternative that is not actually wrong, then by all means share it. To me, it seems like a good choice. Clearly, I am not alone. Greg
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?nospam-1208950264.18834>