All of lore.kernel.org
 help / color / mirror / Atom feed
From: "tip-bot for Kirill A. Shutemov" <kirill@shutemov.name>
To: linux-tip-commits@vger.kernel.org
Cc: acme@redhat.com, linux-kernel@vger.kernel.org, paulus@samba.org,
	hpa@zytor.com, mingo@kernel.org, a.p.zijlstra@chello.nl,
	drepper@gmail.com, tglx@linutronix.de, kirill@shutemov.name
Subject: [tip:perf/core] perf tools: use XSI-complaint version of strerror_r() instead of GNU-specific
Date: Wed, 25 Jul 2012 12:30:03 -0700	[thread overview]
Message-ID: <tip-4cc49d4dc82a39a542a31c1f51ead08a46fd33f1@git.kernel.org> (raw)
In-Reply-To: <20120723210654.GA25248@shutemov.name>

Commit-ID:  4cc49d4dc82a39a542a31c1f51ead08a46fd33f1
Gitweb:     http://git.kernel.org/tip/4cc49d4dc82a39a542a31c1f51ead08a46fd33f1
Author:     Kirill A. Shutemov <kirill@shutemov.name>
AuthorDate: Tue, 24 Jul 2012 00:06:54 +0300
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 25 Jul 2012 11:46:04 -0300

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>
---
 tools/perf/ui/browsers/hists.c |    4 ++--
 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 482f051..413bd62 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)
 	fp = fopen(filename, "w");
 	if (fp == NULL) {
 		char bf[64];
-		strerror_r(errno, bf, sizeof(bf));
-		ui_helpline__fpush("Couldn't write to %s: %s", filename, bf);
+		const char *err = strerror_r(errno, bf, sizeof(bf));
+		ui_helpline__fpush("Couldn't write to %s: %s", filename, err);
 		return -1;
 	}
 
diff --git a/tools/perf/util/target.c b/tools/perf/util/target.c
index 1064d5b..3f59c49 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,
 	int idx;
 	const char *msg;
 
+	BUG_ON(buflen > 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;
 	}
 

  parent reply	other threads:[~2012-07-25 19:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-23 15:00 [PATCH 1/2] perf: fix build error Kirill A. Shutemov
2012-07-23 15:00 ` [PATCH 2/2] perf: use XSI-complaint version of strerror_r() instead of GNU-specific Kirill A. Shutemov
2012-07-23 18:00   ` Ulrich Drepper
2012-07-23 20:31     ` Kirill A. Shutemov
2012-07-23 20:48       ` Ulrich Drepper
2012-07-23 21:06         ` Kirill A. Shutemov
2012-07-23 22:03           ` Ulrich Drepper
2012-07-24  0:56           ` Namhyung Kim
2012-07-25 19:30           ` tip-bot for Kirill A. Shutemov [this message]
2012-07-23 18:02 ` [PATCH 1/2] perf: fix build error Arnaldo Carvalho de Melo
2012-07-23 18:16   ` Kirill A. Shutemov
2012-07-23 18:18     ` Arnaldo Carvalho de Melo
2012-07-23 19:51       ` Kirill A. Shutemov
2012-07-23 21:04         ` Kirill A. Shutemov
2012-07-24  0:38           ` Namhyung Kim
2012-07-25 19:30           ` [tip:perf/core] perf tools: Fix build error with bison 2.6 tip-bot for Kirill A. Shutemov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-4cc49d4dc82a39a542a31c1f51ead08a46fd33f1@git.kernel.org \
    --to=kirill@shutemov.name \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=drepper@gmail.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=paulus@samba.org \
    --cc=tglx@linutronix.de \
    --subject='Re: [tip:perf/core] perf tools: use XSI-complaint version of strerror_r() instead of GNU-specific' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.