All of lore.kernel.org
 help / color / mirror / Atom feed
From: Damien Le Moal <damien.lemoal@wdc.com>
To: Jaegeuk Kim <jaegeuk@kernel.org>, Chao Yu <yuchao0@huawei.com>,
	linux-f2fs-devel@lists.sourceforge.net
Subject: [PATCH 1/5] f2fs-tools: Fix various compilation warnings
Date: Mon, 18 Mar 2019 15:39:55 +0900	[thread overview]
Message-ID: <20190318063959.21369-2-damien.lemoal@wdc.com> (raw)
In-Reply-To: <20190318063959.21369-1-damien.lemoal@wdc.com>

Avoid various compilation warnings due to strncpy:

libf2fs.c:590:33: warning: ‘snprintf’ output may be truncated before
the last format character [-Wformat-truncation=]
  snprintf(rootdev, ret, "/dev/%s", buf);

../include/f2fs_fs.h:1384:2: warning: ‘strncpy’ specified bound
depends on the length of the source argument [-Wstringop-overflow=]
  strncpy(buf, features, strlen(features) + 1);

f2fstat.c:243:3: warning: ‘strncpy’ output truncated before
terminating nul copying as many bytes from a string as its length
[-Wstringop-truncation]
   strncpy(ptr_buf, name[i], strlen(name[i]));

This patch does not change any functionality.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
---
 include/f2fs_fs.h | 6 +++---
 lib/libf2fs.c     | 2 +-
 tools/f2fstat.c   | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index a730688..e073723 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -1379,9 +1379,9 @@ static inline int parse_feature(struct feature *table, const char *features)
 {
 	char *buf, *sub, *next;
 
-	buf = calloc(strlen(features) + 1, sizeof(char));
-	ASSERT(buf);
-	strncpy(buf, features, strlen(features) + 1);
+	buf = strdup(features);
+	if (!buf)
+		return -1;
 
 	for (sub = buf; sub && *sub; sub = next ? next + 1 : NULL) {
 		/* Skip the beginning blanks */
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index c692bf2..60b84e0 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -587,7 +587,7 @@ char *get_rootdev()
 		return NULL;
 	rootdev[ret] = '\0';
 
-	snprintf(rootdev, ret, "/dev/%s", buf);
+	snprintf(rootdev, ret + 1, "/dev/%s", buf);
 	return rootdev;
 #endif
 }
diff --git a/tools/f2fstat.c b/tools/f2fstat.c
index 7f485b0..0618806 100644
--- a/tools/f2fstat.c
+++ b/tools/f2fstat.c
@@ -240,7 +240,7 @@ void print_head(char *res)
 
 	for (i = 0; i < 20; i++) {
 		ptr = (i == 0) ? strtok(res, " ") : strtok(NULL, " ");
-		strncpy(ptr_buf, name[i], strlen(name[i]));
+		strcpy(ptr_buf, name[i]);
 		if (i == 1) {
 			prev_index = ptr_buf - buf - 1;
 		} else if (i == 7) {
-- 
2.20.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

  reply	other threads:[~2019-03-18  6:40 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-18  6:39 [PATCH 0/5] Zoned block device support improvments Damien Le Moal
2019-03-18  6:39 ` Damien Le Moal [this message]
2019-03-21  6:29   ` [PATCH 1/5] f2fs-tools: Fix various compilation warnings Chao Yu
2019-03-18  6:39 ` [PATCH 2/5] f2fs-tools: Add f2fs_io to .gitignore Damien Le Moal
2019-03-21  6:29   ` Chao Yu
2019-03-18  6:39 ` [PATCH 3/5] f2fs-tools: Improve zoned model check Damien Le Moal
2019-03-21  6:32   ` Chao Yu
2019-03-26 18:24   ` Jaegeuk Kim
2019-03-26 22:58     ` Damien Le Moal
2019-03-18  6:39 ` [PATCH 4/5] f2fs-tools: Allow using host-aware devices as regular devices Damien Le Moal
2019-03-21  8:32   ` Chao Yu
2019-03-21  9:29     ` Damien Le Moal
2019-03-21 12:27       ` Chao Yu
2019-03-18  6:39 ` [PATCH 5/5] f2fs-tools: Fix multi-device format with zoned devices Damien Le Moal
2019-03-21  8:41   ` Chao Yu
2019-03-21  9:30     ` Damien Le Moal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190318063959.21369-2-damien.lemoal@wdc.com \
    --to=damien.lemoal@wdc.com \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=yuchao0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.