Skip to content

Commit 144eb3e

Browse files
acmelgregkh
authored andcommitted
perf bench numa: Avoid possible truncation when using snprintf()
commit 3aff8ba0a4c9c9191bb788171a1c54778e1246a2 upstream. Addressing this warning from gcc 7: CC /tmp/build/perf/bench/numa.o bench/numa.c: In function '__bench_numa': bench/numa.c:1582:42: error: '%d' directive output may be truncated writing between 1 and 10 bytes into a region of size between 8 and 17 [-Werror=format-truncation=] snprintf(tname, 32, "process%d:thread%d", p, t); ^~ bench/numa.c:1582:25: note: directive argument in the range [0, 2147483647] snprintf(tname, 32, "process%d:thread%d", p, t); ^~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/stdio.h:939:0, from bench/../util/util.h:47, from bench/../builtin.h:4, from bench/numa.c:11: /usr/include/bits/stdio2.h:64:10: note: '__builtin___snprintf_chk' output between 17 and 35 bytes into a destination of size 32 return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ __bos (__s), __fmt, __va_arg_pack ()); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Petr Holasek <pholasek@redhat.com> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-twa37vsfqcie5gwpqwnjuuz9@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fb3c230 commit 144eb3e

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

tools/perf/bench/numa.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,13 +1570,13 @@ static int __bench_numa(const char *name)
15701570
"GB/sec,", "total-speed", "GB/sec total speed");
15711571

15721572
if (g->p.show_details >= 2) {
1573-
char tname[32];
1573+
char tname[14 + 2 * 10 + 1];
15741574
struct thread_data *td;
15751575
for (p = 0; p < g->p.nr_proc; p++) {
15761576
for (t = 0; t < g->p.nr_threads; t++) {
1577-
memset(tname, 0, 32);
1577+
memset(tname, 0, sizeof(tname));
15781578
td = g->threads + p*g->p.nr_threads + t;
1579-
snprintf(tname, 32, "process%d:thread%d", p, t);
1579+
snprintf(tname, sizeof(tname), "process%d:thread%d", p, t);
15801580
print_res(tname, td->speed_gbs,
15811581
"GB/sec", "thread-speed", "GB/sec/thread speed");
15821582
print_res(tname, td->system_time_ns / 1e9,

0 commit comments

Comments
 (0)