Commit 47efe021 authored by Jiri Olsa's avatar Jiri Olsa Committed by Khalid Elmously

perf tools: Fix snprint warnings for gcc 8

BugLink: https://bugs.launchpad.net/bugs/1889928

commit 77f18153 upstream.

[Add an additional sprintf replacement in tools/perf/builtin-script.c]

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: default avatarJiri 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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarKamal Mostafa <kamal@canonical.com>
Signed-off-by: default avatarKhalid Elmously <khalid.elmously@canonical.com>
parent ed3e4700
...@@ -1245,7 +1245,7 @@ static int is_directory(const char *base_path, const struct dirent *dent) ...@@ -1245,7 +1245,7 @@ static int is_directory(const char *base_path, const struct dirent *dent)
char path[PATH_MAX]; char path[PATH_MAX];
struct stat st; struct stat st;
sprintf(path, "%s/%s", base_path, dent->d_name); scnprintf(path, PATH_MAX, "%s/%s", base_path, dent->d_name);
if (stat(path, &st)) if (stat(path, &st))
return 0; return 0;
...@@ -1426,8 +1426,8 @@ static int list_available_scripts(const struct option *opt __maybe_unused, ...@@ -1426,8 +1426,8 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
return -1; return -1;
for_each_lang(scripts_path, scripts_dir, lang_dirent) { for_each_lang(scripts_path, scripts_dir, lang_dirent) {
snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path, scnprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
lang_dirent->d_name); lang_dirent->d_name);
lang_dir = opendir(lang_path); lang_dir = opendir(lang_path);
if (!lang_dir) if (!lang_dir)
continue; continue;
...@@ -1436,8 +1436,8 @@ static int list_available_scripts(const struct option *opt __maybe_unused, ...@@ -1436,8 +1436,8 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
script_root = get_script_root(script_dirent, REPORT_SUFFIX); script_root = get_script_root(script_dirent, REPORT_SUFFIX);
if (script_root) { if (script_root) {
desc = script_desc__findnew(script_root); desc = script_desc__findnew(script_root);
snprintf(script_path, MAXPATHLEN, "%s/%s", scnprintf(script_path, MAXPATHLEN, "%s/%s",
lang_path, script_dirent->d_name); lang_path, script_dirent->d_name);
read_script_info(desc, script_path); read_script_info(desc, script_path);
free(script_root); free(script_root);
} }
...@@ -1473,7 +1473,7 @@ static int check_ev_match(char *dir_name, char *scriptname, ...@@ -1473,7 +1473,7 @@ static int check_ev_match(char *dir_name, char *scriptname,
int match, len; int match, len;
FILE *fp; FILE *fp;
sprintf(filename, "%s/bin/%s-record", dir_name, scriptname); scnprintf(filename, MAXPATHLEN, "%s/bin/%s-record", dir_name, scriptname);
fp = fopen(filename, "r"); fp = fopen(filename, "r");
if (!fp) if (!fp)
...@@ -1549,8 +1549,8 @@ int find_scripts(char **scripts_array, char **scripts_path_array) ...@@ -1549,8 +1549,8 @@ int find_scripts(char **scripts_array, char **scripts_path_array)
} }
for_each_lang(scripts_path, scripts_dir, lang_dirent) { for_each_lang(scripts_path, scripts_dir, lang_dirent) {
snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path, scnprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
lang_dirent->d_name); lang_dirent->d_name);
#ifdef NO_LIBPERL #ifdef NO_LIBPERL
if (strstr(lang_path, "perl")) if (strstr(lang_path, "perl"))
continue; continue;
...@@ -1605,8 +1605,8 @@ static char *get_script_path(const char *script_root, const char *suffix) ...@@ -1605,8 +1605,8 @@ static char *get_script_path(const char *script_root, const char *suffix)
return NULL; return NULL;
for_each_lang(scripts_path, scripts_dir, lang_dirent) { for_each_lang(scripts_path, scripts_dir, lang_dirent) {
snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path, scnprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
lang_dirent->d_name); lang_dirent->d_name);
lang_dir = opendir(lang_path); lang_dir = opendir(lang_path);
if (!lang_dir) if (!lang_dir)
continue; continue;
...@@ -1617,8 +1617,8 @@ static char *get_script_path(const char *script_root, const char *suffix) ...@@ -1617,8 +1617,8 @@ static char *get_script_path(const char *script_root, const char *suffix)
free(__script_root); free(__script_root);
closedir(lang_dir); closedir(lang_dir);
closedir(scripts_dir); closedir(scripts_dir);
snprintf(script_path, MAXPATHLEN, "%s/%s", scnprintf(script_path, MAXPATHLEN, "%s/%s",
lang_path, script_dirent->d_name); lang_path, script_dirent->d_name);
return strdup(script_path); return strdup(script_path);
} }
free(__script_root); free(__script_root);
......
...@@ -147,8 +147,8 @@ static int run_dir(const char *d, const char *perf) ...@@ -147,8 +147,8 @@ static int run_dir(const char *d, const char *perf)
if (verbose) if (verbose)
vcnt++; vcnt++;
snprintf(cmd, 3*PATH_MAX, PYTHON " %s/attr.py -d %s/attr/ -p %s %.*s", scnprintf(cmd, 3*PATH_MAX, PYTHON " %s/attr.py -d %s/attr/ -p %s %.*s",
d, d, perf, vcnt, v); d, d, perf, vcnt, v);
return system(cmd) ? TEST_FAIL : TEST_OK; return system(cmd) ? TEST_FAIL : TEST_OK;
} }
......
...@@ -95,7 +95,7 @@ static char *test_format_dir_get(void) ...@@ -95,7 +95,7 @@ static char *test_format_dir_get(void)
struct test_format *format = &test_formats[i]; struct test_format *format = &test_formats[i];
FILE *file; FILE *file;
snprintf(name, PATH_MAX, "%s/%s", dir, format->name); scnprintf(name, PATH_MAX, "%s/%s", dir, format->name);
file = fopen(name, "w"); file = fopen(name, "w");
if (!file) if (!file)
......
...@@ -64,7 +64,7 @@ static int open_cgroup(char *name) ...@@ -64,7 +64,7 @@ static int open_cgroup(char *name)
if (cgroupfs_find_mountpoint(mnt, PATH_MAX + 1)) if (cgroupfs_find_mountpoint(mnt, PATH_MAX + 1))
return -1; return -1;
snprintf(path, PATH_MAX, "%s/%s", mnt, name); scnprintf(path, PATH_MAX, "%s/%s", mnt, name);
fd = open(path, O_RDONLY); fd = open(path, O_RDONLY);
if (fd == -1) if (fd == -1)
......
...@@ -194,8 +194,8 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config) ...@@ -194,8 +194,8 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
for_each_event(sys_dirent, evt_dir, evt_dirent) { for_each_event(sys_dirent, evt_dir, evt_dirent) {
snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path, scnprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
evt_dirent->d_name); evt_dirent->d_name);
fd = open(evt_path, O_RDONLY); fd = open(evt_path, O_RDONLY);
if (fd < 0) if (fd < 0)
continue; continue;
......
...@@ -302,7 +302,7 @@ static int pmu_aliases_parse(char *dir, struct list_head *head) ...@@ -302,7 +302,7 @@ static int pmu_aliases_parse(char *dir, struct list_head *head)
if (pmu_alias_info_file(name)) if (pmu_alias_info_file(name))
continue; continue;
snprintf(path, PATH_MAX, "%s/%s", dir, name); scnprintf(path, PATH_MAX, "%s/%s", dir, name);
file = fopen(path, "r"); file = fopen(path, "r");
if (!file) { if (!file) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment