[PATCH 1/2] image: Suppress string truncation warning
Michal Suchanek
msuchanek at suse.de
Wed Oct 12 21:47:24 CEST 2022
In file included from ../tools/imagetool.h:24,
from ../tools/default_image.c:16:
In function ‘image_set_name’,
inlined from ‘image_set_header’ at ../tools/default_image.c:133:2:
../include/image.h:786:9: warning: ‘strncpy’ specified bound 32 equals destination size [-Wstringop-truncation]
786 | strncpy(image_get_name(hdr), name, IH_NMLEN);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There is no standard function that can be used to make the copy without
a warning.
Signed-off-by: Michal Suchanek <msuchanek at suse.de>
---
include/image.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/include/image.h b/include/image.h
index d7d6a3fe5b..e08ef6ed55 100644
--- a/include/image.h
+++ b/include/image.h
@@ -783,7 +783,14 @@ image_set_hdr_b(comp) /* image_set_comp */
static inline void image_set_name(struct legacy_img_hdr *hdr, const char *name)
{
+#if defined(__GNUC__) && (__GNUC__ > 7)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
+#endif
strncpy(image_get_name(hdr), name, IH_NMLEN);
+#if defined(__GNUC__) && (__GNUC__ > 7)
+#pragma GCC diagnostic pop
+#endif
}
int image_check_hcrc(const struct legacy_img_hdr *hdr);
--
2.37.3
More information about the U-Boot
mailing list