When compiling with GCC 9.3 on Ubuntu 20.04 build fails with:
cc -O2 -Wno-error -I. -I/sources/build/elftoolchain-code/readelf -I/sources/build/elftoolchain-code/readelf/../common -I/sources/build/elftoolchain-code/readelf/../libdwarf -I/sources/build/elftoolchain-code/readelf/../libelf -I/sources/build/elftoolchain-code/readelf/../libelftc -Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wno-uninitialized -Wreturn-type -Wcast-qual -Wpointer-arith -Wwrite-strings -Wswitch -Wshadow -Werror -c readelf.c
readelf.c: In function 'timestamp':
readelf.c:2738:52: error: ':' directive output may be truncated writing 1 byte into a region of size between 0 and 16 [-Werror=format-truncation=]
2738 | snprintf(ts, sizeof(ts), "%04d-%02d-%02dT%02d:%02d:%02d",
| ^
In file included from /usr/include/stdio.h:867,
from readelf.c:42:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:67:10: note: '__builtinsnprintfchk' output between 20 and 72 bytes into a destination of size 32
67 | return builtinsnprintfchk (s, __n, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68 | __bos (__s), __fmt, __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
readelf.c: In function 'dump_elf':
readelf.c:4003:39: error: '%02d' directive output may be truncated writing between 2 and 11 bytes into a region of size between 8 and 15 [-Werror=format-truncation=]
4003 | snprintf(tbuf, sizeof(tbuf), "%04d-%02d-%02dT%02d:%02d"
| ^~~~
readelf.c:4003:33: note: directive argument in the range [-2147483647, 2147483647]
4003 | snprintf(tbuf, sizeof(tbuf), "%04d-%02d-%02dT%02d:%02d"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/stdio.h:867,
from readelf.c:42:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:67:10: note: '__builtinsnprintfchk' output between 20 and 72 bytes into a destination of size 20
67 | return builtinsnprintfchk (s, __n, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
68 | __bos (__s), __fmt, __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
Fixed by [r3883].
Related
Commit: [r3883]