From: Bean Huo <huobean@gmail.com>
To: ulf.hansson@linaro.org, adrian.hunter@intel.com,
linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: beanhuo@micron.com
Subject: [PATCH v1 1/2] mmc-utils: Use memcpy instead of strncpy
Date: Sun, 14 Nov 2021 21:43:30 +0100 [thread overview]
Message-ID: <20211114204331.39555-2-huobean@gmail.com> (raw)
In-Reply-To: <20211114204331.39555-1-huobean@gmail.com>
From: Bean Huo <beanhuo@micron.com>
The -Wstringop-truncation warning added in GCC 8.0:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82944
If you use the GCC > v8.0, you probably will get this compilation error:
error: ‘__builtin_strncpy’ output may be truncated copying 8
bytes from a string of length 511 [-Werror=stringop-truncation]
Use memcpy instead of strncpy to avoid this compilation error.
Signed-off-by: Bean Huo <beanhuo@micron.com>
---
mmc_cmds.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mmc_cmds.c b/mmc_cmds.c
index 205e6e5b89f9..ecbde3937c81 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -1835,7 +1835,8 @@ int do_read_extcsd(int nargs, char **argv)
if (ext_csd_rev >= 7) {
memset(lbuf, 0, sizeof(lbuf));
- strncpy(lbuf, (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION], 8);
+ memcpy(lbuf, (char*)&ext_csd[EXT_CSD_FIRMWARE_VERSION], 8);
+ lbuf[8] = '\0';
printf("eMMC Firmware Version: %s\n", lbuf);
printf("eMMC Life Time Estimation A [EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]: 0x%02x\n",
ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A]);
--
2.25.1
next prev parent reply other threads:[~2021-11-14 20:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-14 20:43 [PATCH v1 0/2] Two change for mmc-utils Bean Huo
2021-11-14 20:43 ` Bean Huo [this message]
2021-11-15 7:09 ` [PATCH v1 1/2] mmc-utils: Use memcpy instead of strncpy Ajay Garg
2021-11-15 10:49 ` Bean Huo
2021-11-15 11:37 ` Ajay Garg
2021-11-15 8:38 ` Avri Altman
2021-11-14 20:43 ` [PATCH v1 2/2] mmc-utils: Add note for CMDQ_MODE_EN runtime value Bean Huo
2021-11-15 9:07 ` Avri Altman
2021-11-15 15:08 ` Ulf Hansson
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=20211114204331.39555-2-huobean@gmail.com \
--to=huobean@gmail.com \
--cc=adrian.hunter@intel.com \
--cc=beanhuo@micron.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=ulf.hansson@linaro.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;
as well as URLs for NNTP newsgroup(s).