diff options
| author | Simon Glass <[email protected]> | 2022-11-09 19:14:39 -0700 |
|---|---|---|
| committer | Simon Glass <[email protected]> | 2022-11-22 15:13:34 -0700 |
| commit | 88ff7cb1c8bb411572ac82cd7e312281d8e09d3b (patch) | |
| tree | 8e06262aeed1e10c070271807ee6af79364baf3d /include | |
| parent | fb132b37278c708692dfc3669339ae6d60ee7822 (diff) | |
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 <[email protected]>
Diffstat (limited to 'include')
| -rw-r--r-- | include/image.h | 8 |
1 files changed, 7 insertions, 1 deletions
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); |
