Skip to content

Commit

Permalink
image: Correct strncpy() warning with image_set_name()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
sjg20 authored and DragonBluep committed Nov 14, 2023
1 parent 7d0a2ce commit 3252b45
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,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);
Expand Down

0 comments on commit 3252b45

Please sign in to comment.