aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/util.c
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2014-07-04 07:43:48 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-07-07 15:55:24 -0400
commitd400a68d1f1e7a1fc7c5caf9024d4e67b218558d (patch)
treecba65b9040c912b23d467e9ddf79b23b35fa0c27 /tools/perf/util/util.c
parentf8d9ccde2be4c24bfb8787af36a59a981b00a02d (diff)
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 <andriy.shevchenko@linux.intel.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Link: http://lkml.kernel.org/r/1404474229-15272-1-git-send-email-andriy.shevchenko@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/util.c')
-rw-r--r--tools/perf/util/util.c9
1 files changed, 2 insertions, 7 deletions
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)
333 if (!debugfs) 333 if (!debugfs)
334 return NULL; 334 return NULL;
335 335
336 tracing = malloc(strlen(debugfs) + 9); 336 if (asprintf(&tracing, "%s/tracing", debugfs) < 0)
337 if (!tracing)
338 return NULL; 337 return NULL;
339 338
340 sprintf(tracing, "%s/tracing", debugfs);
341
342 tracing_found = 1; 339 tracing_found = 1;
343 return tracing; 340 return tracing;
344} 341}
@@ -352,11 +349,9 @@ char *get_tracing_file(const char *name)
352 if (!tracing) 349 if (!tracing)
353 return NULL; 350 return NULL;
354 351
355 file = malloc(strlen(tracing) + strlen(name) + 2); 352 if (asprintf(&file, "%s/%s", tracing, name) < 0)
356 if (!file)
357 return NULL; 353 return NULL;
358 354
359 sprintf(file, "%s/%s", tracing, name);
360 return file; 355 return file;
361} 356}
362 357