On 12/10/2022 21.47, Michal Suchanek wrote: > 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); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > There is no standard function that can be used to make the copy without > a warning.
True, but the compiler does give a way to inform that the destination is not _supposed_ to be a nul-terminated string. https://lore.kernel.org/u-boot/dad17a9f-d823-1e8b-3381-539612945...@prevas.dk/ And our include/linux/compiler_attributes.h indeed already exposes that __nonstring attribute. Perhaps try applying that to the ih_name member. It may also be necessary to drop the image_get_name() indirection and just use hdr->ih_name directly; though gcc obviously sees through it to account for the size of the destination buffer (otherwise it couldn't warn), I'm not sure it won't lose that attribute. Rasmus