From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 23 11:57:48 2008 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 515B7106566B for ; Wed, 23 Apr 2008 11:57:48 +0000 (UTC) (envelope-from freebsd-nospam@yaxom.com) Received: from gw.yaxom.com (gw.yaxom.com [59.167.217.197]) by mx1.freebsd.org (Postfix) with SMTP id 6735C8FC0A for ; Wed, 23 Apr 2008 11:57:47 +0000 (UTC) (envelope-from freebsd-nospam@yaxom.com) Received: (qmail 28223 invoked from network); 23 Apr 2008 21:31:04 +1000 Received: from joker.yaxom.com (172.16.1.10) by iliad.yaxom.com with SMTP; 23 Apr 2008 21:31:04 +1000 Received: (qmail 18835 invoked by uid 1001); 23 Apr 2008 21:31:04 +1000 Message-ID: Date: Wed, 23 Apr 2008 21:31:03 +1000 From: Greg Black To: Simun Mikecin References: <251738.1147.qm@web36602.mail.mud.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <251738.1147.qm@web36602.mail.mud.yahoo.com> User-Agent: Mutt/1.4.2.2i; gjb-muttsend.sh 1.7 2004-10-05 X-Uptime: 26 days X-Operating-System: FreeBSD 6.2-RELEASE-p5 i386 X-Location: Brisbane, Australia; 27.49841S 152.98439E X-URL: http://www.yaxom.com/gjb.html X-Blog: http://www.yaxom.com/gjb/blog/ X-Image-URL: http://www.yaxom.com/gjb/gjb-auug048.gif X-PGP-Key-Fingerprint: EBB2 2A92 A79D 1533 AC00 3C46 5D83 B6FB 4B04 B7D6 X-Request-PGP: http://www.yaxom.com/keys/4B04B7D6.asc Cc: hackers@freebsd.org Subject: Re: strdup(NULL) supposed to create SIGSEGV? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Apr 2008 11:57:48 -0000 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