Skip to contentSkip to conversation

perf target: Ignore return value of strerror_r() explicitly

PATCH Superseded Namhyung Kim 3 participants 3 messages Jul 2, 2012 – Jul 3, 2012 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/1 perf target: Ignore return value of strerror_r() explicitly

From: Namhyung Kim <[email protected]>

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

---
 tools/perf/util/target.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/util/target.c +2 -1
index 1064d5b148ad..18080ca9ceec 100644
@@ -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;
 	}
 
Signature · 1 line
1.7.10.2
#1 lore raw

Em Mon, Jul 02, 2012 at 03:20:14PM +0900, Namhyung Kim escreveu:

Quoted 9 lines

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

+++ b/tools/perf/util/target.c

tools/perf/util/target.c int perf_target__strerror(struct perf_target *target, int errnum, · line 115

Quoted 6 lines
tools/perf/util/target.c +2 -1
@@ -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

#2 lore raw
Quoted 19 lines · Arnaldo Carvalho de Melo

Em Mon, Jul 02, 2012 at 03:20:14PM +0900, Namhyung Kim escreveu:

Quoted 9 lines

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

+++ b/tools/perf/util/target.c

tools/perf/util/target.c int perf_target__strerror(struct perf_target *target, int errnum, · line 115

Quoted 6 lines
tools/perf/util/target.c +2 -1
@@ -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?

Quoted 3 lines

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