From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>,
linux-kernel@vger.kernel.org,
"Kirill A. Shutemov" <kirill@shutemov.name>,
Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Ulrich Drepper <drepper@gmail.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: Re: [PATCH 15/19] perf tools: use XSI-complaint version of strerror_r() instead of GNU-specific
Date: Thu, 26 Jul 2012 09:39:59 +0900 [thread overview]
Message-ID: <87lii75p9c.fsf@sejong.aot.lge.com> (raw)
In-Reply-To: <1343238094-12481-16-git-send-email-acme@infradead.org> (Arnaldo Carvalho de Melo's message of "Wed, 25 Jul 2012 14:41:30 -0300")
On Wed, 25 Jul 2012 14:41:30 -0300, Arnaldo Carvalho de Melo wrote:
> From: Kirill A. Shutemov <kirill@shutemov.name>
>
> 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);
> +
No! It should be
BUG_ON(buflen == 0);
Thanks,
Namhyung
> 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;
> }
next prev parent reply other threads:[~2012-07-26 0:45 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-25 17:41 [GIT PULL 00/19] perf/core fixes and improvements Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 01/19] perf symbols: Add machine id to modules debug message Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 02/19] perf kvm: Set name for VM process in guest machine Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 03/19] perf kvm: Guest userspace samples should not be lumped with host uspace Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 04/19] perf kvm: Fix bug resolving guest kernel syms Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 05/19] perf kvm: Limit repetitive guestmount message to once per directory Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 06/19] perf tools: Dump exclude_{guest,host}, precise_ip header info too Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 07/19] perf hists: Return correct number of characters printed in callchain Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 08/19] perf tools: Fix trace events storms due to weight demux Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 09/19] perf hists: Print newline between hists callchains Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 10/19] perf symbols: Factor DSO symtab types to generic binary types Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 11/19] perf symbols: Add interface to read DSO image data Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 12/19] perf symbols: Add dso data caching Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 13/19] perf test: Add dso data caching tests Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 14/19] perf tools: Make the breakpoint events sample period default to 1 Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 15/19] perf tools: use XSI-complaint version of strerror_r() instead of GNU-specific Arnaldo Carvalho de Melo
2012-07-25 17:54 ` Kirill A. Shutemov
2012-07-25 18:23 ` Arnaldo Carvalho de Melo
2012-07-25 18:54 ` Ingo Molnar
2012-07-26 0:39 ` Namhyung Kim [this message]
2012-07-26 1:50 ` [PATCH] perf target: Fix check on buffer size Namhyung Kim
2012-08-05 16:45 ` [tip:perf/urgent] " tip-bot for Namhyung Kim
2012-07-25 17:41 ` [PATCH 16/19] perf tools: Fix build error with bison 2.6 Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 17/19] tools lib traceevent: Detect build environment changes Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 18/19] tools lib traceevent: Ignore TRACEEVENT-CFLAGS file Arnaldo Carvalho de Melo
2012-07-25 17:41 ` [PATCH 19/19] perf annotate: Prevent overflow in size calculation Arnaldo Carvalho de Melo
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=87lii75p9c.fsf@sejong.aot.lge.com \
--to=namhyung@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@infradead.org \
--cc=acme@redhat.com \
--cc=drepper@gmail.com \
--cc=kirill@shutemov.name \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulus@samba.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox