* [tip:perf/core] perf target: Simplify handling of strerror_r return
@ 2015-03-24 16:32 tip-bot for Arnaldo Carvalho de Melo
0 siblings, 0 replies; only message in thread
From: tip-bot for Arnaldo Carvalho de Melo @ 2015-03-24 16:32 UTC (permalink / raw)
To: linux-tip-commits
Cc: tglx, jolsa, namhyung, adrian.hunter, bp, dsahern, dzickus,
fweisbec, acme, linux-kernel, mingo, hpa, eranian
Commit-ID: 17e44dc46f035ca27847bbf75ffd3072ed49f13c
Gitweb: http://git.kernel.org/tip/17e44dc46f035ca27847bbf75ffd3072ed49f13c
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
AuthorDate: Mon, 23 Mar 2015 18:23:02 -0300
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 24 Mar 2015 12:08:30 -0300
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 <jolsa@redhat.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-d0ik6i5gjew56j0qphql28ou@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/util/target.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/tools/perf/util/target.c b/tools/perf/util/target.c
index e74c596..a53603b 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;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-03-24 16:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-24 16:32 [tip:perf/core] perf target: Simplify handling of strerror_r return tip-bot for Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®