All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf target: Ignore return value of strerror_r() explicitly
@ 2012-07-02  6:20 Namhyung Kim
  2012-07-02 15:34 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Namhyung Kim @ 2012-07-02  6:20 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, LKML,
	Markus Trippelsdorf, Namhyung Kim

From: Namhyung Kim <namhyung.kim@lge.com>

Since glibc 2.16 added the warn_unused_result (wur) attribute
to the function, we should check the return value or ignore it
explicitly.

Reported-by: Markus Trippelsdorf <markus@trippelsdorf.de>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 tools/perf/util/target.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/target.c b/tools/perf/util/target.c
index 1064d5b148ad..18080ca9ceec 100644
--- a/tools/perf/util/target.c
+++ b/tools/perf/util/target.c
@@ -111,7 +111,8 @@ int perf_target__strerror(struct perf_target *target, int errnum,
 	const char *msg;
 
 	if (errnum >= 0) {
-		strerror_r(errnum, buf, buflen);
+		/* make glibc (>= 2.16) happy */
+		(void)strerror_r(errnum, buf, buflen);
 		return 0;
 	}
 
-- 
1.7.10.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf target: Ignore return value of strerror_r() explicitly
  2012-07-02  6:20 [PATCH] perf target: Ignore return value of strerror_r() explicitly Namhyung Kim
@ 2012-07-02 15:34 ` Arnaldo Carvalho de Melo
  2012-07-03  0:28   ` Namhyung Kim
  0 siblings, 1 reply; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2012-07-02 15:34 UTC (permalink / raw)
  To: Namhyung Kim
  Cc: Peter Zijlstra, Paul Mackerras, Ingo Molnar, LKML,
	Markus Trippelsdorf, Namhyung Kim

Em Mon, Jul 02, 2012 at 03:20:14PM +0900, Namhyung Kim escreveu:
> Since glibc 2.16 added the warn_unused_result (wur) attribute
> to the function, we should check the return value or ignore it
> explicitly.
> 
> Reported-by: Markus Trippelsdorf <markus@trippelsdorf.de>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>

> +++ b/tools/perf/util/target.c
> @@ -111,7 +111,8 @@ int perf_target__strerror(struct perf_target *target, int errnum,
>  	const char *msg;
>  
>  	if (errnum >= 0) {
> -		strerror_r(errnum, buf, buflen);
> +		/* make glibc (>= 2.16) happy */
> +		(void)strerror_r(errnum, buf, buflen);

Is this really the best way to handle this?

What if some perf tool is buggy and passes an invalid errnum?  Shouldn't
we catch that?

- Arnaldo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf target: Ignore return value of strerror_r() explicitly
  2012-07-02 15:34 ` Arnaldo Carvalho de Melo
@ 2012-07-03  0:28   ` Namhyung Kim
  0 siblings, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2012-07-03  0:28 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Namhyung Kim, Peter Zijlstra, Paul Mackerras, Ingo Molnar, LKML,
	Markus Trippelsdorf

2012-07-03 12:34 AM, Arnaldo Carvalho de Melo wrote:
> Em Mon, Jul 02, 2012 at 03:20:14PM +0900, Namhyung Kim escreveu:
>> Since glibc 2.16 added the warn_unused_result (wur) attribute
>> to the function, we should check the return value or ignore it
>> explicitly.
>>
>> Reported-by: Markus Trippelsdorf <markus@trippelsdorf.de>
>> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
>
>> +++ b/tools/perf/util/target.c
>> @@ -111,7 +111,8 @@ int perf_target__strerror(struct perf_target *target, int errnum,
>>   	const char *msg;
>>
>>   	if (errnum >= 0) {
>> -		strerror_r(errnum, buf, buflen);
>> +		/* make glibc (>= 2.16) happy */
>> +		(void)strerror_r(errnum, buf, buflen);
>
> Is this really the best way to handle this?
>
> What if some perf tool is buggy and passes an invalid errnum?  Shouldn't
> we catch that?
>

$ man strerror_r
...
RETURN VALUE
        The  strerror()  and  the  GNU-specific strerror_r() functions
        return the appropriate error description string, or an
        "Unknown error nnn" message if the error number is unknown.

Isn't it sufficient? Or we can reset the @buf at the beginning for the case of 
a invalid negative @errnum.

Thanks,
Namhyung


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-07-03  0:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-02  6:20 [PATCH] perf target: Ignore return value of strerror_r() explicitly Namhyung Kim
2012-07-02 15:34 ` Arnaldo Carvalho de Melo
2012-07-03  0:28   ` Namhyung Kim

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.