[PATCH v2 1/2] image: Fix string truncation warning

Michal Suchanek msuchanek at suse.de
Thu Oct 13 10:16:56 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);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Michal Suchanek <msuchanek at suse.de>
---

Changes in v2:
Use __nonstring instead of suppressing the warning

---
 include/image.h  | 3 ++-
 tools/kwbimage.h | 6 ------
 2 files changed, 2 insertions(+), 7 deletions(-)

diff --git a/include/image.h b/include/image.h
index d7d6a3fe5b..82b447aeb7 100644
--- a/include/image.h
+++ b/include/image.h
@@ -18,6 +18,7 @@
 #include "compiler.h"
 #include <asm/byteorder.h>
 #include <stdbool.h>
+#include <linux/compiler_attributes.h>
 
 /* Define this to avoid #ifdefs later on */
 struct lmb;
@@ -275,7 +276,7 @@ struct legacy_img_hdr {
 	uint8_t		ih_arch;	/* CPU architecture		*/
 	uint8_t		ih_type;	/* Image Type			*/
 	uint8_t		ih_comp;	/* Compression Type		*/
-	uint8_t		ih_name[IH_NMLEN];	/* Image Name		*/
+	uint8_t		ih_name[IH_NMLEN] __nonstring;	/* Image Name	*/
 };
 
 struct image_info {
diff --git a/tools/kwbimage.h b/tools/kwbimage.h
index 505522332b..327ca34494 100644
--- a/tools/kwbimage.h
+++ b/tools/kwbimage.h
@@ -11,12 +11,6 @@
 #include <compiler.h>
 #include <stdint.h>
 
-#ifdef __GNUC__
-#define __packed __attribute((packed))
-#else
-#define __packed
-#endif
-
 #define KWBIMAGE_MAX_CONFIG	((0x1dc - 0x20)/sizeof(struct reg_config))
 #define MAX_TEMPBUF_LEN		32
 
-- 
2.37.3



More information about the U-Boot mailing list