From d400a68d1f1e7a1fc7c5caf9024d4e67b218558d Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Fri, 4 Jul 2014 14:43:48 +0300 Subject: perf tools: Convert open coded equivalents to asprintf() The following snippet V = malloc(S); if (!V) { } sprintf(V, ...) Can be easily changed to a one line: if (asprintf(&V, ...) < 0) { } Signed-off-by: Andy Shevchenko Cc: Adrian Hunter Link: http://lkml.kernel.org/r/1404474229-15272-1-git-send-email-andriy.shevchenko@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/util.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'tools/perf/util/util.c') diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 95aefa78bb07..e4132aeeb780 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -333,12 +333,9 @@ const char *find_tracing_dir(void) if (!debugfs) return NULL; - tracing = malloc(strlen(debugfs) + 9); - if (!tracing) + if (asprintf(&tracing, "%s/tracing", debugfs) < 0) return NULL; - sprintf(tracing, "%s/tracing", debugfs); - tracing_found = 1; return tracing; } @@ -352,11 +349,9 @@ char *get_tracing_file(const char *name) if (!tracing) return NULL; - file = malloc(strlen(tracing) + strlen(name) + 2); - if (!file) + if (asprintf(&file, "%s/%s", tracing, name) < 0) return NULL; - sprintf(file, "%s/%s", tracing, name); return file; } -- cgit v1.2.3-59-g8ed1b