From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Andries E. Brouwer" Subject: Re: [PATCH] partitions: Prefer strlcpy() over snprintf() Date: Thu, 10 Jul 2008 14:28:01 +0200 Message-ID: <20080710122801.GD30891@mette> References: <20080710133004.26c0b991@hyperion.delvare> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Andries Brouwer , linux-fsdevel@vger.kernel.org To: Jean Delvare Return-path: Received: from hera.cwi.nl ([192.16.191.8]:55067 "EHLO hera.cwi.nl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753883AbYGJM4K (ORCPT ); Thu, 10 Jul 2008 08:56:10 -0400 Content-Disposition: inline In-Reply-To: <20080710133004.26c0b991@hyperion.delvare> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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.