error: '%s' directive output may be truncated
Status: Beta
Brought to you by:
seranian
Due to changes on gcc, perfmon2 does not compile anymore on current systems:
Compiling for 'x86_64' target Compiling for 'Linux' system make[1]: Entering directory '/home/thomas/JKU/perfmon2-libpfm4/lib' cc -g -Wall -Werror -Wextra -Wno-unused-parameter -I. -I/home/thomas/JKU/perfmon2-libpfm4/lib/../include -DCONFIG_PFMLIB_DEBUG -DCONFIG_PFMLIB_OS_LINUX -D_REENTRANT -I. -fvisibility=hidden -DCONFIG_PFMLIB_ARCH_X86 -DCONFIG_PFMLIB_ARCH_X86_64 -I. -c pfmlib_perf_event_pmu.c pfmlib_perf_event_pmu.c: In function 'gen_tracepoint_table': pfmlib_perf_event_pmu.c:354:36: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=] snprintf(d2path, MAXPATHLEN, "%s/%s", debugfs_mnt, d1->d_name); ^~ pfmlib_perf_event_pmu.c:354:3: note: 'snprintf' output between 2 and 4352 bytes into a destination of size 4096 snprintf(d2path, MAXPATHLEN, "%s/%s", debugfs_mnt, d1->d_name); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pfmlib_perf_event_pmu.c:404:58: error: '%s' directive output may be truncated writing up to 255 bytes into a region of size between 0 and 4095 [-Werror=format-truncation=] snprintf(idpath, MAXPATHLEN, "%s/%s/id", d2path, d2->d_name); ^~ pfmlib_perf_event_pmu.c:404:25: note: 'snprintf' output between 5 and 4355 bytes into a destination of size 4096 snprintf(idpath, MAXPATHLEN, "%s/%s/id", d2path, d2->d_name); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors make[1]: *** [/home/thomas/JKU/perfmon2-libpfm4/lib/../rules.mk:30: pfmlib_perf_event_pmu.o] Error 1 make[1]: Leaving directory '/home/thomas/JKU/perfmon2-libpfm4/lib' make: *** [Makefile:49: all] Error 2
cc -v Using built-in specs. COLLECT_GCC=cc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/8.1.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp Thread model: posix gcc version 8.1.0 (GCC)
It can be silenced by appending -Wno-format-truncation
to the CFLAGS
of the Makefiles located in ./lib/
and ./perf_examples/
.
I'm running on an up-to-date Arch-Linux System
Rather than disabling the gcc truncation check maybe have something like the attached patch to check the return values of snprintf to see if they are in the expected range.
Fixed in: https://sourceforge.net/p/perfmon2/libpfm4/ci/29f626744df184913a200532408e205e2b0ec2ec/
please close issue