forked from Minki/linux
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>
This commit is contained in:
parent
4a841d650e
commit
4cc49d4dc8
@ -978,8 +978,8 @@ static int hist_browser__dump(struct hist_browser *browser)
|
|||||||
fp = fopen(filename, "w");
|
fp = fopen(filename, "w");
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
char bf[64];
|
char bf[64];
|
||||||
strerror_r(errno, bf, sizeof(bf));
|
const char *err = strerror_r(errno, bf, sizeof(bf));
|
||||||
ui_helpline__fpush("Couldn't write to %s: %s", filename, bf);
|
ui_helpline__fpush("Couldn't write to %s: %s", filename, err);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,8 +110,17 @@ int perf_target__strerror(struct perf_target *target, int errnum,
|
|||||||
int idx;
|
int idx;
|
||||||
const char *msg;
|
const char *msg;
|
||||||
|
|
||||||
|
BUG_ON(buflen > 0);
|
||||||
|
|
||||||
if (errnum >= 0) {
|
if (errnum >= 0) {
|
||||||
strerror_r(errnum, buf, buflen);
|
const char *err = strerror_r(errnum, buf, buflen);
|
||||||
|
|
||||||
|
if (err != buf) {
|
||||||
|
size_t len = strlen(err);
|
||||||
|
char *c = mempcpy(buf, err, min(buflen - 1, len));
|
||||||
|
*c = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user