From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 23 07:38:35 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 D59A31065673 for ; Wed, 23 Apr 2008 07:38:35 +0000 (UTC) (envelope-from mureninc@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.152]) by mx1.freebsd.org (Postfix) with ESMTP id 739708FC1B for ; Wed, 23 Apr 2008 07:38:35 +0000 (UTC) (envelope-from mureninc@gmail.com) Received: by fg-out-1718.google.com with SMTP id 16so2713846fgg.35 for ; Wed, 23 Apr 2008 00:38:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=0iSy2rcREd4srskPObTmfipv4sWaHSM5hz9Iy5pAvA0=; b=N6d1dPQwPMZ9O6nFzT2m1aCChCwe1zk1GYkMzhh9l+Vw8ZUx9HXpV6Y4bSO0V2zmfRM21gjZN/RyVLak9IoY1zkDRddbMlq7epInT2PLhK9DxTds4k2tAtsgSJe69USVwsVidH0w9cyRGcGRKBPoYZaVL6XPM1EuUIROVteEKvY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=PhYm3epH6wDzw/mzrpQ7nSQozUm+Pi3kPZNsQgJTdWcPxJhCUnJ8OcppKJfwx0LgpeqW5Toe/j6YKxGSkDp6nxBgdEj/LvbGHUI1PUKAm9szK/fiwx49BDFgxl2XuF98w5PQ98vKpUY5CVbmIOLpXmliiNG2+lvJuF7YEoyi0B0= Received: by 10.86.50.8 with SMTP id x8mr2526074fgx.30.1208934794209; Wed, 23 Apr 2008 00:13:14 -0700 (PDT) Received: by 10.86.72.3 with HTTP; Wed, 23 Apr 2008 00:13:14 -0700 (PDT) Message-ID: Date: Wed, 23 Apr 2008 03:13:14 -0400 From: "Constantine A. Murenin" To: "Garrett Cooper" In-Reply-To: <7d6fde3d0804222240j6b42b77yd86d8accb5a959fa@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <7d6fde3d0804222240j6b42b77yd86d8accb5a959fa@mail.gmail.com> 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:38:35 -0000 On 23/04/2008, 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? > 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.