]> git.ipfire.org Git - thirdparty/elfutils.git/commit
readelf: Workaround stringop-truncation error
authorMark Wielaard <mark@klomp.org>
Sat, 4 Dec 2021 00:08:48 +0000 (01:08 +0100)
committerMark Wielaard <mark@klomp.org>
Wed, 8 Dec 2021 23:11:36 +0000 (00:11 +0100)
commit3e1e249bfd8455457716cce798f3f91d01f2f00d
tree470a814ca962773121010673487ed9db692d2a64
parent00d1c798b5225af732ecace438d4895ce6d6d24e
readelf: Workaround stringop-truncation error

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.

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/readelf.c