From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 23 18:56:34 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 91469106567F; Wed, 23 Apr 2008 18:56:34 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe14.swipnet.se [212.247.155.161]) by mx1.freebsd.org (Postfix) with ESMTP id D2CF98FC22; Wed, 23 Apr 2008 18:56:33 +0000 (UTC) (envelope-from hselasky@c2i.net) X-Cloudmark-Score: 0.000000 [] Received: from [62.113.133.152] (account mc467741@c2i.net [62.113.133.152] verified) by mailfe14.swip.net (CommuniGate Pro SMTP 5.1.13) with ESMTPA id 170495761; Wed, 23 Apr 2008 19:56:29 +0200 From: Hans Petter Selasky To: freebsd-hackers@freebsd.org Date: Wed, 23 Apr 2008 19:57:47 +0200 User-Agent: KMail/1.9.7 References: <293918.47889.qm@web36608.mail.mud.yahoo.com> <20080423124023.54ca505e@mbook-fbsd> In-Reply-To: <20080423124023.54ca505e@mbook-fbsd> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200804231957.49035.hselasky@c2i.net> Cc: Simun Mikecin , Mike Meyer , 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 18:56:34 -0000 Hi, I recently had to tell someone that "strncpy" does not always zero terminate the destination string. Surprised by what I was telling they immediately wanted to change the way the function worked. When a function is defined by an ISO standard you are not supposed to change the definition. Instead I pointed the person at "strlcpy". Else you will have serious trouble when code is ported to a new platform. http://www.gratisoft.us/todd/papers/strlcpy.html The name "strdup" is very appealing, but it has already been taken and defined. You have to give your variant a different name and convince everyone that your function is good and solves a problem so that it deserves to be in the C-library. Then you simply run a script on your code: sed -s "s/ strdup[(]/ strsdup(/g" *.[ch] --HPS :-)