From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Tom Rini <trini@konsulko.com>,
Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
Simon Glass <sjg@chromium.org>,
Andre Przywara <andre.przywara@arm.com>,
Heinrich Schuchardt <xypron.glpk@gmx.de>,
Jan Kiszka <jan.kiszka@siemens.com>,
Joe Hershberger <joe.hershberger@ni.com>,
Marek Vasut <marex@denx.de>,
Philippe Reynes <philippe.reynes@softathome.com>,
Sean Anderson <sean.anderson@seco.com>,
Steven Lawrance <steven.lawrance@softathome.com>
Subject: [PATCH v5 01/16] image: Correct strncpy() warning with image_set_name()
Date: Wed, 9 Nov 2022 19:14:39 -0700 [thread overview]
Message-ID: <20221110021455.1004335-2-sjg@chromium.org> (raw)
In-Reply-To: <20221110021455.1004335-1-sjg@chromium.org>
gcc 12 seems to warn on strncpy() as a matter of course. Rewrite the code
a different way to do the same thing, to avoid the warning.
Signed-off-by: Simon Glass <sjg@chromium.org>
---
(no changes since v1)
include/image.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/include/image.h b/include/image.h
index 65d0d4f4387..6f21dafba8c 100644
--- a/include/image.h
+++ b/include/image.h
@@ -853,7 +853,13 @@ image_set_hdr_b(comp) /* image_set_comp */
static inline void image_set_name(struct legacy_img_hdr *hdr, const char *name)
{
- strncpy(image_get_name(hdr), name, IH_NMLEN);
+ /*
+ * This is equivalent to: strncpy(image_get_name(hdr), name, IH_NMLEN);
+ *
+ * Use the tortured code below to avoid a warning with gcc 12. We do not
+ * want to include a nul terminator if the name is of length IH_NMLEN
+ */
+ memcpy(image_get_name(hdr), name, strnlen(name, IH_NMLEN));
}
int image_check_hcrc(const struct legacy_img_hdr *hdr);
--
2.38.1.431.g37b22c650d-goog
next prev parent reply other threads:[~2022-11-10 2:16 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-10 2:14 [PATCH v5 00/16] buildman: Correct various issues with missing blobs Simon Glass
2022-11-10 2:14 ` Simon Glass [this message]
2022-11-23 2:12 ` [PATCH v5 01/16] image: Correct strncpy() warning with image_set_name() Simon Glass
2022-11-10 2:14 ` [PATCH v5 02/16] Makefile: Correct the binman rule Simon Glass
2022-11-10 8:01 ` Pali Rohár
2022-11-10 20:40 ` Simon Glass
2022-11-23 2:11 ` Simon Glass
2022-11-10 2:14 ` [PATCH v5 03/16] doc: Correct the path to the Makefile documentation Simon Glass
2022-11-23 2:11 ` Simon Glass
2022-11-10 2:14 ` [PATCH v5 04/16] binman: Use an exit code when blobs are missing Simon Glass
2022-11-23 2:11 ` Simon Glass
2022-11-10 2:14 ` [PATCH v5 05/16] buildman: Convert documentation to rST Simon Glass
2022-11-23 2:11 ` Simon Glass
2022-11-10 2:14 ` [PATCH v5 06/16] buildman: Drop mention of MAKEALL Simon Glass
2022-11-23 2:11 ` Simon Glass
2022-11-10 2:14 ` [PATCH v5 07/16] buildman: Update the arc toolchain Simon Glass
2022-11-23 2:11 ` Simon Glass
2022-11-10 2:14 ` [PATCH v5 08/16] buildman: Update the default settings file Simon Glass
2022-11-23 2:11 ` Simon Glass
2022-11-10 2:14 ` [PATCH v5 09/16] buildman: Drop mention of old architectures Simon Glass
2022-11-23 2:11 ` Simon Glass
2022-11-10 2:14 ` [PATCH v5 10/16] buildman: Detect binman reporting missing blobs Simon Glass
2022-11-23 2:11 ` Simon Glass
2022-12-05 23:13 ` Peter Robinson
2022-12-05 23:23 ` Tom Rini
2022-12-05 23:29 ` Peter Robinson
2022-12-05 23:34 ` Tom Rini
2022-12-05 23:43 ` Peter Robinson
2022-12-05 23:46 ` Tom Rini
2022-12-05 23:49 ` Peter Robinson
2022-12-05 23:55 ` Simon Glass
2022-12-05 23:56 ` Tom Rini
2022-12-05 23:57 ` Simon Glass
2022-11-10 2:14 ` [PATCH v5 11/16] binman: Add a separate section about environment variables Simon Glass
2022-11-23 2:11 ` Simon Glass
2022-11-10 2:14 ` [PATCH v5 12/16] global: Do not default to faking missing binaries for buildman Simon Glass
2022-11-23 2:11 ` Simon Glass
2022-11-10 2:14 ` [PATCH v5 13/16] buildman: Ensure config_fname is inited Simon Glass
2022-11-23 2:11 ` Simon Glass
2022-11-10 2:14 ` [PATCH v5 14/16] buildman: Reinstate removal of temp output dir in tests Simon Glass
2022-11-23 2:11 ` Simon Glass
2022-11-10 2:14 ` [PATCH v5 15/16] buildman: Add --allow-missing flag to allow missing blobs Simon Glass
2022-11-23 2:11 ` Simon Glass
2022-11-10 2:14 ` [PATCH v5 16/16] binman: Add documentation for the command line args Simon Glass
2022-11-23 2:11 ` Simon Glass
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=20221110021455.1004335-2-sjg@chromium.org \
--to=sjg@chromium.org \
--cc=andre.przywara@arm.com \
--cc=jan.kiszka@siemens.com \
--cc=joe.hershberger@ni.com \
--cc=marex@denx.de \
--cc=philippe.reynes@softathome.com \
--cc=rasmus.villemoes@prevas.dk \
--cc=sean.anderson@seco.com \
--cc=steven.lawrance@softathome.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/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.