From: Simon Glass Date: Thu, 10 Nov 2022 02:14:39 +0000 (-0700) Subject: image: Correct strncpy() warning with image_set_name() X-Git-Tag: accepted/tizen/unified/riscv/20230821.130836~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a001021645ee5172ae3dcc8d49c64f72077bf4b5;p=platform%2Fkernel%2Fu-boot.git image: Correct strncpy() warning with image_set_name() 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 [sw0312.kim: cherry-pick upstream commit 88ff7cb1c8bb4 to remove gcc-13 build warning] Signed-off-by: Seung-Woo Kim Change-Id: Idda3d015e81fd39d33de1cfc13cc19f78404a5a1 --- diff --git a/include/image.h b/include/image.h index d7d756c645..6c0dffd3ce 100644 --- a/include/image.h +++ b/include/image.h @@ -776,7 +776,13 @@ image_set_hdr_b(comp) /* image_set_comp */ static inline void image_set_name(image_header_t *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 image_header_t *hdr);