lkml.org 
[lkml]   [2013]   [Dec]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 3/7] perf tools: Use asprintf instead of malloc plus snprintf
Date
asprintf is equivalent to malloc plus snprintf so
use it because it is simpler.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/util/srcline.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/tools/perf/util/srcline.c b/tools/perf/util/srcline.c
index d11aefb..4c8e816 100644
--- a/tools/perf/util/srcline.c
+++ b/tools/perf/util/srcline.c
@@ -227,7 +227,6 @@ char *get_srcline(struct dso *dso, unsigned long addr)
unsigned line = 0;
char *srcline;
char *dso_name = dso->long_name;
- size_t size;

if (!dso->has_srcline)
return SRCLINE_UNKNOWN;
@@ -241,13 +240,7 @@ char *get_srcline(struct dso *dso, unsigned long addr)
if (!addr2line(dso_name, addr, &file, &line))
goto out;

- /* just calculate actual length */
- size = snprintf(NULL, 0, "%s:%u", file, line) + 1;
-
- srcline = malloc(size);
- if (srcline)
- snprintf(srcline, size, "%s:%u", file, line);
- else
+ if (asprintf(&srcline, "%s:%u", file, line) < 0)
srcline = SRCLINE_UNKNOWN;

free(file);
--
1.7.11.7


\
 
 \ /
  Last update: 2013-12-03 08:21    [W:0.119 / U:0.848 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site