[PATCH 1/2] image: Suppress string truncation warning

Michal Suchánek msuchanek at suse.de
Thu Oct 13 10:12:09 CEST 2022


On Thu, Oct 13, 2022 at 09:29:22AM +0200, Rasmus Villemoes wrote:
> 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-53961294521c@prevas.dk/
> 
> And our include/linux/compiler_attributes.h indeed already exposes that
> __nonstring attribute. Perhaps try applying that to the ih_name member.

That's better, that's an actual fix.

Thanks

Michal


More information about the U-Boot mailing list