From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 23 11:26:26 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7C98F1065672 for ; Wed, 23 Apr 2008 11:26:26 +0000 (UTC) (envelope-from modelnine@modelnine.org) Received: from jord.modelnine.org (jord.modelnine.org [83.246.72.120]) by mx1.freebsd.org (Postfix) with ESMTP id 367268FC21 for ; Wed, 23 Apr 2008 11:26:26 +0000 (UTC) (envelope-from modelnine@modelnine.org) Received: from [192.168.1.37] (unknown [89.182.20.21]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: modelnine) by jord.modelnine.org (Postfix) with ESMTPSA id B54F2A47260 for ; Wed, 23 Apr 2008 13:26:24 +0200 (CEST) From: Heiko Wundram To: freebsd-hackers@freebsd.org Date: Wed, 23 Apr 2008 13:28:23 +0200 User-Agent: KMail/1.9.7 References: <251738.1147.qm@web36602.mail.mud.yahoo.com> In-Reply-To: <251738.1147.qm@web36602.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200804231328.23777.modelnine@modelnine.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:26:26 -0000 Am Mittwoch, 23. April 2008 11:38:54 schrieb Simun Mikecin: > >Yes, it's supposed to segfault. Check out what, say, strcpy does if > >you ask it to copy a NULL pointer. And this is an improvement from the > >bad old days, when they would happily walk through memory starting at > >0..... > >Besides, errno is used to signal errors from system calls. strdup > >isn't a system call, it's a library function (says so at the top of > >the man page). > >Do you have examples of systems where strdup doesn't behave this way? > > According to Open Group strdup should return NULL and set errno. Look at: > http://www.opengroup.org/onlinepubs/009695399/functions/strdup.html > > There is no valid argument for doing segfault instead of above behavior. Read the standard closely. If you pass in something that is defined as having undefined behaviour (a NULL pointer is defined in such a way at other points of the standard), do not expect to get defined behaviour out. What the standard talks about is when the memory for the duplicate string cannot be allocated, WHEN you pass in a valid pointer. -- Heiko Wundram