aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2018-03-19 04:29:01 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-03-19 09:00:43 -0400
commit77f18153c080855e1c3fb520ca31a4e61530121d (patch)
treee667525893ac4fe6eadb83c02b3381fb950dfa7a /tools
parenta08f6dd4190e90dc7b013435acb66770f117e8b0 (diff)
perf tools: Fix snprint warnings for gcc 8
With gcc 8 we get new set of snprintf() warnings that breaks the compilation, one example: tests/mem.c: In function ‘check’: tests/mem.c:19:48: error: ‘%s’ directive output may be truncated writing \ up to 99 bytes into a region of size 89 [-Werror=format-truncation=] snprintf(failure, sizeof failure, "unexpected %s", out); The gcc docs says: To avoid the warning either use a bigger buffer or handle the function's return value which indicates whether or not its output has been truncated. Given that all these warnings are harmless, because the code either properly fails due to uncomplete file path or we don't care for truncated output at all, I'm changing all those snprintf() calls to scnprintf(), which actually 'checks' for the snprint return value so the gcc stays silent. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com> Link: http://lkml.kernel.org/r/20180319082902.4518-1-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-script.c22
-rw-r--r--tools/perf/tests/attr.c4
-rw-r--r--tools/perf/tests/mem.c2
-rw-r--r--tools/perf/tests/pmu.c2
-rw-r--r--tools/perf/util/cgroup.c2
-rw-r--r--tools/perf/util/parse-events.c4
-rw-r--r--tools/perf/util/pmu.c2
7 files changed, 19 insertions, 19 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index cce926aeb0c0..313c42423393 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2674,8 +2674,8 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
2674 } 2674 }
2675 2675
2676 for_each_lang(scripts_path, scripts_dir, lang_dirent) { 2676 for_each_lang(scripts_path, scripts_dir, lang_dirent) {
2677 snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path, 2677 scnprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
2678 lang_dirent->d_name); 2678 lang_dirent->d_name);
2679 lang_dir = opendir(lang_path); 2679 lang_dir = opendir(lang_path);
2680 if (!lang_dir) 2680 if (!lang_dir)
2681 continue; 2681 continue;
@@ -2684,8 +2684,8 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
2684 script_root = get_script_root(script_dirent, REPORT_SUFFIX); 2684 script_root = get_script_root(script_dirent, REPORT_SUFFIX);
2685 if (script_root) { 2685 if (script_root) {
2686 desc = script_desc__findnew(script_root); 2686 desc = script_desc__findnew(script_root);
2687 snprintf(script_path, MAXPATHLEN, "%s/%s", 2687 scnprintf(script_path, MAXPATHLEN, "%s/%s",
2688 lang_path, script_dirent->d_name); 2688 lang_path, script_dirent->d_name);
2689 read_script_info(desc, script_path); 2689 read_script_info(desc, script_path);
2690 free(script_root); 2690 free(script_root);
2691 } 2691 }
@@ -2721,7 +2721,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
2721 int match, len; 2721 int match, len;
2722 FILE *fp; 2722 FILE *fp;
2723 2723
2724 sprintf(filename, "%s/bin/%s-record", dir_name, scriptname); 2724 scnprintf(filename, MAXPATHLEN, "%s/bin/%s-record", dir_name, scriptname);
2725 2725
2726 fp = fopen(filename, "r"); 2726 fp = fopen(filename, "r");
2727 if (!fp) 2727 if (!fp)
@@ -2799,8 +2799,8 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
2799 } 2799 }
2800 2800
2801 for_each_lang(scripts_path, scripts_dir, lang_dirent) { 2801 for_each_lang(scripts_path, scripts_dir, lang_dirent) {
2802 snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path, 2802 scnprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
2803 lang_dirent->d_name); 2803 lang_dirent->d_name);
2804#ifdef NO_LIBPERL 2804#ifdef NO_LIBPERL
2805 if (strstr(lang_path, "perl")) 2805 if (strstr(lang_path, "perl"))
2806 continue; 2806 continue;
@@ -2855,8 +2855,8 @@ static char *get_script_path(const char *script_root, const char *suffix)
2855 return NULL; 2855 return NULL;
2856 2856
2857 for_each_lang(scripts_path, scripts_dir, lang_dirent) { 2857 for_each_lang(scripts_path, scripts_dir, lang_dirent) {
2858 snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path, 2858 scnprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
2859 lang_dirent->d_name); 2859 lang_dirent->d_name);
2860 lang_dir = opendir(lang_path); 2860 lang_dir = opendir(lang_path);
2861 if (!lang_dir) 2861 if (!lang_dir)
2862 continue; 2862 continue;
@@ -2867,8 +2867,8 @@ static char *get_script_path(const char *script_root, const char *suffix)
2867 free(__script_root); 2867 free(__script_root);
2868 closedir(lang_dir); 2868 closedir(lang_dir);
2869 closedir(scripts_dir); 2869 closedir(scripts_dir);
2870 snprintf(script_path, MAXPATHLEN, "%s/%s", 2870 scnprintf(script_path, MAXPATHLEN, "%s/%s",
2871 lang_path, script_dirent->d_name); 2871 lang_path, script_dirent->d_name);
2872 return strdup(script_path); 2872 return strdup(script_path);
2873 } 2873 }
2874 free(__script_root); 2874 free(__script_root);
diff --git a/tools/perf/tests/attr.c b/tools/perf/tests/attr.c
index 97f64ad7fa08..05dfe11c2f9e 100644
--- a/tools/perf/tests/attr.c
+++ b/tools/perf/tests/attr.c
@@ -170,8 +170,8 @@ static int run_dir(const char *d, const char *perf)
170 if (verbose > 0) 170 if (verbose > 0)
171 vcnt++; 171 vcnt++;
172 172
173 snprintf(cmd, 3*PATH_MAX, PYTHON " %s/attr.py -d %s/attr/ -p %s %.*s", 173 scnprintf(cmd, 3*PATH_MAX, PYTHON " %s/attr.py -d %s/attr/ -p %s %.*s",
174 d, d, perf, vcnt, v); 174 d, d, perf, vcnt, v);
175 175
176 return system(cmd) ? TEST_FAIL : TEST_OK; 176 return system(cmd) ? TEST_FAIL : TEST_OK;
177} 177}
diff --git a/tools/perf/tests/mem.c b/tools/perf/tests/mem.c
index 21952e1e6e6d..0f82ee9fd3f7 100644
--- a/tools/perf/tests/mem.c
+++ b/tools/perf/tests/mem.c
@@ -16,7 +16,7 @@ static int check(union perf_mem_data_src data_src,
16 16
17 n = perf_mem__snp_scnprintf(out, sizeof out, &mi); 17 n = perf_mem__snp_scnprintf(out, sizeof out, &mi);
18 n += perf_mem__lvl_scnprintf(out + n, sizeof out - n, &mi); 18 n += perf_mem__lvl_scnprintf(out + n, sizeof out - n, &mi);
19 snprintf(failure, sizeof failure, "unexpected %s", out); 19 scnprintf(failure, sizeof failure, "unexpected %s", out);
20 TEST_ASSERT_VAL(failure, !strcmp(string, out)); 20 TEST_ASSERT_VAL(failure, !strcmp(string, out));
21 return 0; 21 return 0;
22} 22}
diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c
index 9abca267afa9..7bedf8608fdd 100644
--- a/tools/perf/tests/pmu.c
+++ b/tools/perf/tests/pmu.c
@@ -98,7 +98,7 @@ static char *test_format_dir_get(void)
98 struct test_format *format = &test_formats[i]; 98 struct test_format *format = &test_formats[i];
99 FILE *file; 99 FILE *file;
100 100
101 snprintf(name, PATH_MAX, "%s/%s", dir, format->name); 101 scnprintf(name, PATH_MAX, "%s/%s", dir, format->name);
102 102
103 file = fopen(name, "w"); 103 file = fopen(name, "w");
104 if (!file) 104 if (!file)
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index 78408f5c4bad..decb91f9da82 100644
--- a/tools/perf/util/cgroup.c
+++ b/tools/perf/util/cgroup.c
@@ -81,7 +81,7 @@ static int open_cgroup(const char *name)
81 if (cgroupfs_find_mountpoint(mnt, PATH_MAX + 1)) 81 if (cgroupfs_find_mountpoint(mnt, PATH_MAX + 1))
82 return -1; 82 return -1;
83 83
84 snprintf(path, PATH_MAX, "%s/%s", mnt, name); 84 scnprintf(path, PATH_MAX, "%s/%s", mnt, name);
85 85
86 fd = open(path, O_RDONLY); 86 fd = open(path, O_RDONLY);
87 if (fd == -1) 87 if (fd == -1)
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 4e80ca320399..2fb0272146d8 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -206,8 +206,8 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
206 206
207 for_each_event(sys_dirent, evt_dir, evt_dirent) { 207 for_each_event(sys_dirent, evt_dir, evt_dirent) {
208 208
209 snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, 209 scnprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
210 evt_dirent->d_name); 210 evt_dirent->d_name);
211 fd = open(evt_path, O_RDONLY); 211 fd = open(evt_path, O_RDONLY);
212 if (fd < 0) 212 if (fd < 0)
213 continue; 213 continue;
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 1111d5bf15ca..064bdcb7bd78 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -351,7 +351,7 @@ static int pmu_aliases_parse(char *dir, struct list_head *head)
351 if (pmu_alias_info_file(name)) 351 if (pmu_alias_info_file(name))
352 continue; 352 continue;
353 353
354 snprintf(path, PATH_MAX, "%s/%s", dir, name); 354 scnprintf(path, PATH_MAX, "%s/%s", dir, name);
355 355
356 file = fopen(path, "r"); 356 file = fopen(path, "r");
357 if (!file) { 357 if (!file) {