]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
image: Correct strncpy() warning with image_set_name()
authorSimon Glass <sjg@chromium.org>
Thu, 10 Nov 2022 02:14:39 +0000 (19:14 -0700)
committerSimon Glass <sjg@chromium.org>
Tue, 22 Nov 2022 22:13:34 +0000 (15:13 -0700)
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>
include/image.h

index 65d0d4f4387d2dbcdee2f470f02a581d0bf176ad..6f21dafba8cec53ebe133a8cfb486e915b8024bb 100644 (file)
@@ -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);