[PATCH] readelf: Workaround stringop-truncation error

Mark Wielaard mark@klomp.org
Wed Dec 8 23:14:13 GMT 2021


On Sat, Dec 04, 2021 at 10:15:04PM +0100, Mark Wielaard wrote:
> In function ‘strncpy’,
>     inlined from ‘print_ehdr’ at readelf.c:1175:4:
> error: ‘__builtin_strncpy’ specified bound 512 equals destination size
>        [-Werror=stringop-truncation]
> 
> strncpy doesn't terminate the copied string if there is not enough
> room. We compensate later by explicitly adding a zero terminator at
> buf[sizeof (buf) - 1]. Normally gcc does see this, but with
> -fsanitize=address there is too much (checking) code in between. But
> it is actually better to not let strncpy do too much work, so
> substract one from the size.

Pushed,

Mark


More information about the Elfutils-devel mailing list