diff options
author | Kirill A. Shutemov <kirill@shutemov.name> | 2012-07-23 17:06:54 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-07-25 10:46:04 -0400 |
commit | 4cc49d4dc82a39a542a31c1f51ead08a46fd33f1 (patch) | |
tree | d8fbb02c3e31e326b9f4bd63574fac56bb7b2eb3 /tools/perf | |
parent | 4a841d650ea435c69e60675537f158a620697290 (diff) |
perf tools: use XSI-complaint version of strerror_r() instead of GNU-specific
Perf uses GNU-specific version of strerror_r(). The GNU-specific strerror_r()
returns a pointer to a string containing the error message. This may be either
a pointer to a string that the function stores in buf, or a pointer to some
(immutable) static string (in which case buf is unused).
In glibc-2.16 GNU version was marked with attribute warn_unused_result. It
triggers few warnings in perf:
util/target.c: In function ‘perf_target__strerror’:
util/target.c:114:13: error: ignoring return value of ‘strerror_r’, declared with attribute warn_unused_result [-Werror=unused-result]
ui/browsers/hists.c: In function ‘hist_browser__dump’:
ui/browsers/hists.c:981:13: error: ignoring return value of ‘strerror_r’, declared with attribute warn_unused_result [-Werror=unused-result]
They are bugs.
Let's fix strerror_r() usage.
Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Acked-by: Ulrich Drepper <drepper@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Ulrich Drepper <drepper@gmail.com>
Link: http://lkml.kernel.org/r/20120723210654.GA25248@shutemov.name
[ committer note: s/assert/BUG_ON/g ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/ui/browsers/hists.c | 4 | ||||
-rw-r--r-- | tools/perf/util/target.c | 11 |
2 files changed, 12 insertions, 3 deletions
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c index 482f0517b61e..413bd62eedb1 100644 --- a/tools/perf/ui/browsers/hists.c +++ b/tools/perf/ui/browsers/hists.c | |||
@@ -978,8 +978,8 @@ static int hist_browser__dump(struct hist_browser *browser) | |||
978 | fp = fopen(filename, "w"); | 978 | fp = fopen(filename, "w"); |
979 | if (fp == NULL) { | 979 | if (fp == NULL) { |
980 | char bf[64]; | 980 | char bf[64]; |
981 | strerror_r(errno, bf, sizeof(bf)); | 981 | const char *err = strerror_r(errno, bf, sizeof(bf)); |
982 | ui_helpline__fpush("Couldn't write to %s: %s", filename, bf); | 982 | ui_helpline__fpush("Couldn't write to %s: %s", filename, err); |
983 | return -1; | 983 | return -1; |
984 | } | 984 | } |
985 | 985 | ||
diff --git a/tools/perf/util/target.c b/tools/perf/util/target.c index 1064d5b148ad..3f59c496e64c 100644 --- a/tools/perf/util/target.c +++ b/tools/perf/util/target.c | |||
@@ -110,8 +110,17 @@ int perf_target__strerror(struct perf_target *target, int errnum, | |||
110 | int idx; | 110 | int idx; |
111 | const char *msg; | 111 | const char *msg; |
112 | 112 | ||
113 | BUG_ON(buflen > 0); | ||
114 | |||
113 | if (errnum >= 0) { | 115 | if (errnum >= 0) { |
114 | strerror_r(errnum, buf, buflen); | 116 | const char *err = strerror_r(errnum, buf, buflen); |
117 | |||
118 | if (err != buf) { | ||
119 | size_t len = strlen(err); | ||
120 | char *c = mempcpy(buf, err, min(buflen - 1, len)); | ||
121 | *c = '\0'; | ||
122 | } | ||
123 | |||
115 | return 0; | 124 | return 0; |
116 | } | 125 | } |
117 | 126 | ||