aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <[email protected]>2015-03-23 21:23:02 +0000
committerArnaldo Carvalho de Melo <[email protected]>2015-03-24 15:08:30 +0000
commit17e44dc46f035ca27847bbf75ffd3072ed49f13c (patch)
treed067492224b46395beccdf48c1d75fd8552dad50
parentperf tools: Work around lack of sched_getcpu in glibc < 2.6. (diff)
downloadkernel-17e44dc46f035ca27847bbf75ffd3072ed49f13c.tar.gz
kernel-17e44dc46f035ca27847bbf75ffd3072ed49f13c.zip
perf target: Simplify handling of strerror_r return
To deal with forwarding the strerror_r (GNU) return we need to check if the returned value is the buffer we passed or maybe some constant (unknown error), simplify that action by using scnprintf, that will do all the buflen size checks, trimming if needed. Acked-by: Jiri Olsa <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: David Ahern <[email protected]> Cc: Don Zickus <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
-rw-r--r--tools/perf/util/target.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/tools/perf/util/target.c b/tools/perf/util/target.c
index e74c5963dc7a..a53603b27e52 100644
--- a/tools/perf/util/target.c
+++ b/tools/perf/util/target.c
@@ -123,11 +123,8 @@ int target__strerror(struct target *target, int errnum,
if (errnum >= 0) {
const char *err = strerror_r(errnum, buf, buflen);
- if (err != buf) {
- size_t len = strlen(err);
- memcpy(buf, err, min(buflen - 1, len));
- *(buf + min(buflen - 1, len)) = '\0';
- }
+ if (err != buf)
+ scnprintf(buf, buflen, "%s", err);
return 0;
}