diff options
author | Jiri Olsa <jolsa@kernel.org> | 2018-07-02 09:42:01 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-07-11 09:39:57 -0400 |
commit | a09603f851045b031e990d2d663958ccb49db525 (patch) | |
tree | 4f897ef7da19d05ceb3ad64c4f8d7f72103c28ba /tools/perf | |
parent | db8fec583f250557ddd6def1505a6c466c9747aa (diff) |
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 <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/20180702134202.17745-1-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/arch/x86/util/perf_regs.c | 2 | ||||
-rw-r--r-- | tools/perf/jvmti/jvmti_agent.c | 3 |
2 files changed, 3 insertions, 2 deletions
diff --git a/tools/perf/arch/x86/util/perf_regs.c b/tools/perf/arch/x86/util/perf_regs.c index 4b2caf6d48e7..fead6b3b4206 100644 --- a/tools/perf/arch/x86/util/perf_regs.c +++ b/tools/perf/arch/x86/util/perf_regs.c | |||
@@ -226,7 +226,7 @@ int arch_sdt_arg_parse_op(char *old_op, char **new_op) | |||
226 | else if (rm[2].rm_so != rm[2].rm_eo) | 226 | else if (rm[2].rm_so != rm[2].rm_eo) |
227 | prefix[0] = '+'; | 227 | prefix[0] = '+'; |
228 | else | 228 | else |
229 | strncpy(prefix, "+0", 2); | 229 | scnprintf(prefix, sizeof(prefix), "+0"); |
230 | } | 230 | } |
231 | 231 | ||
232 | /* Rename register */ | 232 | /* Rename register */ |
diff --git a/tools/perf/jvmti/jvmti_agent.c b/tools/perf/jvmti/jvmti_agent.c index 0c6d1002b524..ac1bcdc17dae 100644 --- a/tools/perf/jvmti/jvmti_agent.c +++ b/tools/perf/jvmti/jvmti_agent.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <sys/mman.h> | 35 | #include <sys/mman.h> |
36 | #include <syscall.h> /* for gettid() */ | 36 | #include <syscall.h> /* for gettid() */ |
37 | #include <err.h> | 37 | #include <err.h> |
38 | #include <linux/kernel.h> | ||
38 | 39 | ||
39 | #include "jvmti_agent.h" | 40 | #include "jvmti_agent.h" |
40 | #include "../util/jitdump.h" | 41 | #include "../util/jitdump.h" |
@@ -249,7 +250,7 @@ void *jvmti_open(void) | |||
249 | /* | 250 | /* |
250 | * jitdump file name | 251 | * jitdump file name |
251 | */ | 252 | */ |
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()); |
253 | 254 | ||
254 | fd = open(dump_path, O_CREAT|O_TRUNC|O_RDWR, 0666); | 255 | fd = open(dump_path, O_CREAT|O_TRUNC|O_RDWR, 0666); |
255 | if (fd == -1) | 256 | if (fd == -1) |