Skip to content

Commit a09603f

Browse files
olsajiriacmel
authored andcommitted
perf tools: Fix compilation errors on gcc8
We are getting following warnings on gcc8 that break compilation: $ make CC jvmti/jvmti_agent.o jvmti/jvmti_agent.c: In function ‘jvmti_open’: jvmti/jvmti_agent.c:252:35: error: ‘/jit-’ directive output may be truncated \ writing 5 bytes into a region of size between 1 and 4096 [-Werror=format-truncation=] snprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid()); There's no point in checking the result of snprintf call in jvmti_open, the following open call will fail in case the name is mangled or too long. Using tools/lib/ function scnprintf that touches the return value from the snprintf() calls and thus get rid of those warnings. $ make DEBUG=1 CC arch/x86/util/perf_regs.o arch/x86/util/perf_regs.c: In function ‘arch_sdt_arg_parse_op’: arch/x86/util/perf_regs.c:229:4: error: ‘strncpy’ output truncated before terminating nul copying 2 bytes from a string of the same length [-Werror=stringop-truncation] strncpy(prefix, "+0", 2); ^~~~~~~~~~~~~~~~~~~~~~~~ Using scnprintf instead of the strncpy (which we know is safe in here) to get rid of that warning. Signed-off-by: Jiri Olsa <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: David Ahern <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent db8fec5 commit a09603f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

tools/perf/arch/x86/util/perf_regs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ int arch_sdt_arg_parse_op(char *old_op, char **new_op)
226226
else if (rm[2].rm_so != rm[2].rm_eo)
227227
prefix[0] = '+';
228228
else
229-
strncpy(prefix, "+0", 2);
229+
scnprintf(prefix, sizeof(prefix), "+0");
230230
}
231231

232232
/* Rename register */

tools/perf/jvmti/jvmti_agent.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <sys/mman.h>
3636
#include <syscall.h> /* for gettid() */
3737
#include <err.h>
38+
#include <linux/kernel.h>
3839

3940
#include "jvmti_agent.h"
4041
#include "../util/jitdump.h"
@@ -249,7 +250,7 @@ void *jvmti_open(void)
249250
/*
250251
* jitdump file name
251252
*/
252-
snprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid());
253+
scnprintf(dump_path, PATH_MAX, "%s/jit-%i.dump", jit_path, getpid());
253254

254255
fd = open(dump_path, O_CREAT|O_TRUNC|O_RDWR, 0666);
255256
if (fd == -1)

0 commit comments

Comments
 (0)