From: Stafford Horne <shorne@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Greg KH <gregkh@linuxfoundation.org>,
arnd@arndb.de, Eric Biggers <ebiggers3@gmail.com>,
linux-crypto@vger.kernel.org, Stafford Horne <shorne@gmail.com>
Subject: [PATCH v2 2/2] kobject: Fix -Wstringop-truncation warning
Date: Mon, 25 Jun 2018 21:45:38 +0900 [thread overview]
Message-ID: <20180625124538.21051-3-shorne@gmail.com> (raw)
In-Reply-To: <20180625124538.21051-1-shorne@gmail.com>
When compiling with GCC 9.0.0 I am seeing the following warning:
In function ‘fill_kobj_path’,
inlined from ‘kobject_get_path’ at lib/kobject.c:155:2:
lib/kobject.c:128:3: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
strncpy(path + length, kobject_name(parent), cur);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lib/kobject.c: In function ‘kobject_get_path’:
lib/kobject.c:125:13: note: length computed here
int cur = strlen(kobject_name(parent));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
This is not really an issue since the buffer we are writing to is
pre-zero'd and we have already allocated the buffer based on the
calculated strlen size and accounted for the terminating '\0'.
Just use memcpy() instead.
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Eric Biggers <ebiggers3@gmail.com>
Signed-off-by: Stafford Horne <shorne@gmail.com>
---
lib/kobject.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/kobject.c b/lib/kobject.c
index 18989b5b3b56..e876957743c8 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -125,7 +125,7 @@ static void fill_kobj_path(struct kobject *kobj, char *path, int length)
int cur = strlen(kobject_name(parent));
/* back up enough to print this name with '/' */
length -= cur;
- strncpy(path + length, kobject_name(parent), cur);
+ memcpy(path + length, kobject_name(parent), cur);
*(path + --length) = '/';
}
--
2.17.0
next prev parent reply other threads:[~2018-06-25 12:45 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-25 12:45 [PATCH v2 0/2] Fix GCC -Wstringop-truncation warnings Stafford Horne
2018-06-25 12:45 ` [PATCH v2 1/2] crypto: Fix " Stafford Horne
2018-06-25 12:59 ` Christophe LEROY
2018-06-25 13:40 ` Stafford Horne
2018-07-08 16:43 ` Herbert Xu
2018-06-25 12:45 ` Stafford Horne [this message]
2018-06-25 12:57 ` [PATCH v2 2/2] kobject: Fix -Wstringop-truncation warning Christophe LEROY
2018-06-25 13:24 ` Stafford Horne
2018-06-25 13:32 ` Christophe LEROY
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=20180625124538.21051-3-shorne@gmail.com \
--to=shorne@gmail.com \
--cc=arnd@arndb.de \
--cc=ebiggers3@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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