From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 23 07:18:55 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 88A65106564A for ; Wed, 23 Apr 2008 07:18:55 +0000 (UTC) (envelope-from mwm-keyword-freebsdhackers2.e313df@mired.org) Received: from mired.org (student.mired.org [66.92.153.77]) by mx1.freebsd.org (Postfix) with ESMTP id 14C668FC3D for ; Wed, 23 Apr 2008 07:18:54 +0000 (UTC) (envelope-from mwm-keyword-freebsdhackers2.e313df@mired.org) Received: (qmail 41941 invoked by uid 1001); 23 Apr 2008 02:50:51 -0400 Received: from bhuda.mired.org (192.168.195.1) by bhuda.mired.org (tmda-ofmipd) with ESMTP; Wed, 23 Apr 2008 02:50:50 -0400 Date: Wed, 23 Apr 2008 02:50:48 -0400 To: "Garrett Cooper" Message-ID: <20080423025048.6b51a580@bhuda.mired.org> In-Reply-To: <7d6fde3d0804222240j6b42b77yd86d8accb5a959fa@mail.gmail.com> References: <7d6fde3d0804222240j6b42b77yd86d8accb5a959fa@mail.gmail.com> Organization: Meyer Consulting X-Mailer: Claws Mail 3.3.1 (GTK+ 2.12.9; amd64-portbld-freebsd7.0) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Delivery-Agent: TMDA/1.1.12 (Macallan) From: Mike Meyer 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 07:18:55 -0000 On Tue, 22 Apr 2008 22:40:21 -0700 "Garrett Cooper" 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? 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). > Good news is that Linux does the same thing (yay?), so at least FreeBSD > isn't alone.. Do you have examples of systems where strdup doesn't behave this way? http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information.