[PATCH] partitions: Prefer strlcpy() over snprintf()

Previous thread: [patch v2] splice: fix race with page invalidation by Miklos Szeredi on Tuesday, July 8, 2008 - 4:39 pm. (1 message)

Next thread: [PATCH] vfs: fix vfs_rename_dir for FS_RENAME_DOES_D_MOVE filesystems by Sage Weil on Friday, July 11, 2008 - 3:47 pm. (6 messages)
To: Andries Brouwer <aeb@...>
Cc: <linux-fsdevel@...>
Date: Thursday, July 10, 2008 - 7:30 am

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
--

To: Jean Delvare <khali@...>
Cc: Andries Brouwer <Andries.Brouwer@...>, <linux-fsdevel@...>
Date: Thursday, July 10, 2008 - 8:28 am

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.

--

To: Andries E. Brouwer <Andries.Brouwer@...>
Cc: <linux-fsdevel@...>
Date: Thursday, July 10, 2008 - 9:03 am

[Empty message]
Previous thread: [patch v2] splice: fix race with page invalidation by Miklos Szeredi on Tuesday, July 8, 2008 - 4:39 pm. (1 message)

Next thread: [PATCH] vfs: fix vfs_rename_dir for FS_RENAME_DOES_D_MOVE filesystems by Sage Weil on Friday, July 11, 2008 - 3:47 pm. (6 messages)