From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jean Delvare Subject: Re: [PATCH] partitions: Prefer strlcpy() over snprintf() Date: Thu, 10 Jul 2008 15:03:15 +0200 Message-ID: <20080710150315.18c925fe@hyperion.delvare> References: <20080710133004.26c0b991@hyperion.delvare> <20080710122801.GD30891@mette> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: linux-fsdevel@vger.kernel.org To: "Andries E. Brouwer" Return-path: Received: from zone0.gcu-squad.org ([212.85.147.21]:26537 "EHLO services.gcu-squad.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754102AbYGJNDX (ORCPT ); Thu, 10 Jul 2008 09:03:23 -0400 In-Reply-To: <20080710122801.GD30891@mette> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Hi Andries, On Thu, 10 Jul 2008 14:28:01 +0200, Andries E. Brouwer wrote: > On Thu, Jul 10, 2008 at 01:30:04PM +0200, Jean Delvare wrote: > > Subject: partitions: Prefer strlcpy() over snprintf() > > > > strlcpy is faster than snprintf when you don't use the returned value. > > > if (!part) > > - snprintf(buf, BDEVNAME_SIZE, "%s", hd->disk_name); > > + strlcpy(buf, hd->disk_name, BDEVNAME_SIZE); > > else if (isdigit(hd->disk_name[strlen(hd->disk_name)-1])) > > snprintf(buf, BDEVNAME_SIZE, "%sp%d", hd->disk_name, part); > > else > > Yecch. There is a parallelism between the two cases > which makes the source nice and readable. > You want to destroy the parallelism for no gain. > Different functions, different parameter order. Ach. At the moment I hit "Send" I thought about that and suspected that someone would object for that reason. And that makes sense, indeed. Just scratch this patch, sorry for the noise. -- Jean Delvare