* [PATCH] partitions: Prefer strlcpy() over snprintf()
@ 2008-07-10 11:30 Jean Delvare
2008-07-10 12:28 ` Andries E. Brouwer
0 siblings, 1 reply; 3+ messages in thread
From: Jean Delvare @ 2008-07-10 11:30 UTC (permalink / raw)
To: Andries Brouwer; +Cc: linux-fsdevel
Subject: partitions: Prefer strlcpy() over snprintf()
strlcpy is faster than snprintf when you don't use the returned value.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Andries Brouwer <aeb@cwi.nl>
---
This patch was already sent on:
* 2008-05-09
fs/partitions/check.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- linux-2.6.26-rc1.orig/fs/partitions/check.c 2008-05-09 17:35:37.000000000 +0200
+++ linux-2.6.26-rc1/fs/partitions/check.c 2008-05-09 17:39:13.000000000 +0200
@@ -123,7 +123,7 @@ static int (*check_part[])(struct parsed
char *disk_name(struct gendisk *hd, int part, char *buf)
{
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
--
Jean Delvare
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] partitions: Prefer strlcpy() over snprintf()
2008-07-10 11:30 [PATCH] partitions: Prefer strlcpy() over snprintf() Jean Delvare
@ 2008-07-10 12:28 ` Andries E. Brouwer
2008-07-10 13:03 ` Jean Delvare
0 siblings, 1 reply; 3+ messages in thread
From: Andries E. Brouwer @ 2008-07-10 12:28 UTC (permalink / raw)
To: Jean Delvare; +Cc: Andries Brouwer, linux-fsdevel
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] partitions: Prefer strlcpy() over snprintf()
2008-07-10 12:28 ` Andries E. Brouwer
@ 2008-07-10 13:03 ` Jean Delvare
0 siblings, 0 replies; 3+ messages in thread
From: Jean Delvare @ 2008-07-10 13:03 UTC (permalink / raw)
To: Andries E. Brouwer; +Cc: linux-fsdevel
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-07-10 13:03 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-10 11:30 [PATCH] partitions: Prefer strlcpy() over snprintf() Jean Delvare
2008-07-10 12:28 ` Andries E. Brouwer
2008-07-10 13:03 ` Jean Delvare
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.