[PATCH 4.14 109/109] perf tools: Fix snprint warnings for gcc 8

2018-10-16 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Jiri Olsa 

commit 77f18153c080855e1c3fb520ca31a4e61530121d upstream.

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 
Cc: Alexander Shishkin 
Cc: David Ahern 
Cc: Josh Poimboeuf 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Sergey Senozhatsky 
Link: http://lkml.kernel.org/r/20180319082902.4518-1-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
Cc: Ignat Korchagin 
Signed-off-by: Greg Kroah-Hartman 

---
 tools/perf/builtin-script.c|   22 +++---
 tools/perf/tests/attr.c|4 ++--
 tools/perf/tests/mem.c |2 +-
 tools/perf/tests/pmu.c |2 +-
 tools/perf/util/cgroup.c   |2 +-
 tools/perf/util/parse-events.c |4 ++--
 tools/perf/util/pmu.c  |2 +-
 7 files changed, 19 insertions(+), 19 deletions(-)

--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2304,8 +2304,8 @@ static int list_available_scripts(const
}
 
for_each_lang(scripts_path, scripts_dir, lang_dirent) {
-   snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
-lang_dirent->d_name);
+   scnprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
+ lang_dirent->d_name);
lang_dir = opendir(lang_path);
if (!lang_dir)
continue;
@@ -2314,8 +2314,8 @@ static int list_available_scripts(const
script_root = get_script_root(script_dirent, 
REPORT_SUFFIX);
if (script_root) {
desc = script_desc__findnew(script_root);
-   snprintf(script_path, MAXPATHLEN, "%s/%s",
-lang_path, script_dirent->d_name);
+   scnprintf(script_path, MAXPATHLEN, "%s/%s",
+ lang_path, script_dirent->d_name);
read_script_info(desc, script_path);
free(script_root);
}
@@ -2351,7 +2351,7 @@ static int check_ev_match(char *dir_name
int match, len;
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");
if (!fp)
@@ -2427,8 +2427,8 @@ int find_scripts(char **scripts_array, c
}
 
for_each_lang(scripts_path, scripts_dir, lang_dirent) {
-   snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
-lang_dirent->d_name);
+   scnprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
+ lang_dirent->d_name);
 #ifdef NO_LIBPERL
if (strstr(lang_path, "perl"))
continue;
@@ -2483,8 +2483,8 @@ static char *get_script_path(const char
return NULL;
 
for_each_lang(scripts_path, scripts_dir, lang_dirent) {
-   snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
-lang_dirent->d_name);
+   scnprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
+ lang_dirent->d_name);
lang_dir = opendir(lang_path);
if (!lang_dir)
continue;
@@ -2495,8 +2495,8 @@ static char *get_script_path(const char
free(__script_root);
closedir(lang_dir);
closedir(scripts_dir);
-   snprintf(script_path, MAXPATHLEN, "%s/%s",
-lang_path, script_dirent->d_name);
+   scnprintf(script_path, MAXPATHLEN, "%s/%s",
+ lang_path, script_dirent->d_name);
return strdup(script_path);
}
free(__script_root);
--- a/tools/perf/tests/attr.c
+++ b/tools/perf/tests/attr.c
@@ -164,8 +164,8 @@ 

[PATCH 4.14 109/109] perf tools: Fix snprint warnings for gcc 8

2018-10-16 Thread Greg Kroah-Hartman
4.14-stable review patch.  If anyone has any objections, please let me know.

--

From: Jiri Olsa 

commit 77f18153c080855e1c3fb520ca31a4e61530121d upstream.

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 
Cc: Alexander Shishkin 
Cc: David Ahern 
Cc: Josh Poimboeuf 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Sergey Senozhatsky 
Link: http://lkml.kernel.org/r/20180319082902.4518-1-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
Cc: Ignat Korchagin 
Signed-off-by: Greg Kroah-Hartman 

---
 tools/perf/builtin-script.c|   22 +++---
 tools/perf/tests/attr.c|4 ++--
 tools/perf/tests/mem.c |2 +-
 tools/perf/tests/pmu.c |2 +-
 tools/perf/util/cgroup.c   |2 +-
 tools/perf/util/parse-events.c |4 ++--
 tools/perf/util/pmu.c  |2 +-
 7 files changed, 19 insertions(+), 19 deletions(-)

--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2304,8 +2304,8 @@ static int list_available_scripts(const
}
 
for_each_lang(scripts_path, scripts_dir, lang_dirent) {
-   snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
-lang_dirent->d_name);
+   scnprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
+ lang_dirent->d_name);
lang_dir = opendir(lang_path);
if (!lang_dir)
continue;
@@ -2314,8 +2314,8 @@ static int list_available_scripts(const
script_root = get_script_root(script_dirent, 
REPORT_SUFFIX);
if (script_root) {
desc = script_desc__findnew(script_root);
-   snprintf(script_path, MAXPATHLEN, "%s/%s",
-lang_path, script_dirent->d_name);
+   scnprintf(script_path, MAXPATHLEN, "%s/%s",
+ lang_path, script_dirent->d_name);
read_script_info(desc, script_path);
free(script_root);
}
@@ -2351,7 +2351,7 @@ static int check_ev_match(char *dir_name
int match, len;
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");
if (!fp)
@@ -2427,8 +2427,8 @@ int find_scripts(char **scripts_array, c
}
 
for_each_lang(scripts_path, scripts_dir, lang_dirent) {
-   snprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
-lang_dirent->d_name);
+   scnprintf(lang_path, MAXPATHLEN, "%s/%s", scripts_path,
+ lang_dirent->d_name);
 #ifdef NO_LIBPERL
if (strstr(lang_path, "perl"))
continue;
@@ -2483,8 +2483,8 @@ static char *get_script_path(const char
return NULL;
 
for_each_lang(scripts_path, scripts_dir, lang_dirent) {
-   snprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
-lang_dirent->d_name);
+   scnprintf(lang_path, MAXPATHLEN, "%s/%s/bin", scripts_path,
+ lang_dirent->d_name);
lang_dir = opendir(lang_path);
if (!lang_dir)
continue;
@@ -2495,8 +2495,8 @@ static char *get_script_path(const char
free(__script_root);
closedir(lang_dir);
closedir(scripts_dir);
-   snprintf(script_path, MAXPATHLEN, "%s/%s",
-lang_path, script_dirent->d_name);
+   scnprintf(script_path, MAXPATHLEN, "%s/%s",
+ lang_path, script_dirent->d_name);
return strdup(script_path);
}
free(__script_root);
--- a/tools/perf/tests/attr.c
+++ b/tools/perf/tests/attr.c
@@ -164,8 +164,8 @@