mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xiongfeng Wang <wangxiongfeng2@huawei.com>
To: <lars@metafoo.de>, <pmeerw@pmeerw.net>, <linux-iio@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>, <arnd@arndb.de>,
	<wangxiongfeng2@huawei.com>
Subject: [PATCH] iio: accel: use strlcpy() instead of strncpy()
Date: Fri, 12 Jan 2018 15:45:38 +0800	[thread overview]
Message-ID: <1515743138-94480-1-git-send-email-wangxiongfeng2@huawei.com> (raw)

From: Xiongfeng Wang <xiongfeng.wang@linaro.org>

gcc-8 reports

drivers/iio/accel/st_accel_i2c.c: In function 'st_accel_i2c_probe':
./include/linux/string.h:245:9: warning: '__builtin_strncpy' specified
bound 20 equals destination size [-Wstringop-truncation]

The compiler require that the length of the dest string is greater than
the length we want to copy to make sure the dest string is
nul-terminated. We can just use strlcpy() to avoid this warning.

Signed-off-by: Xiongfeng Wang <xiongfeng.wang@linaro.org>
---
 drivers/iio/accel/st_accel_i2c.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c
index 363429b..6bdec8c 100644
--- a/drivers/iio/accel/st_accel_i2c.c
+++ b/drivers/iio/accel/st_accel_i2c.c
@@ -159,9 +159,8 @@ static int st_accel_i2c_probe(struct i2c_client *client,
 		if ((ret < 0) || (ret >= ST_ACCEL_MAX))
 			return -ENODEV;
 
-		strncpy(client->name, st_accel_id_table[ret].name,
+		strlcpy(client->name, st_accel_id_table[ret].name,
 				sizeof(client->name));
-		client->name[sizeof(client->name) - 1] = '\0';
 	} else if (!id)
 		return -ENODEV;
 
-- 
1.8.3.1

             reply	other threads:[~2018-01-12  7:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-12  7:45 Xiongfeng Wang [this message]
2018-01-14 12:02 ` Jonathan Cameron

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=1515743138-94480-1-git-send-email-wangxiongfeng2@huawei.com \
    --to=wangxiongfeng2@huawei.com \
    --cc=arnd@arndb.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®