[cairo] [PATCH 08/12] Use xstrdup instead of xmalloc when possible

Andrea Canciani ranma42 at gmail.com
Sat Nov 12 13:20:00 PST 2011


Don't open code xstrdup, just use it.
---
 perf/cairo-perf-report.c |    6 ++----
 test/cairo-test.c        |   10 ++--------
 2 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/perf/cairo-perf-report.c b/perf/cairo-perf-report.c
index 8df78c6..38bdc0c 100644
--- a/perf/cairo-perf-report.c
+++ b/perf/cairo-perf-report.c
@@ -388,11 +388,9 @@ cairo_perf_report_load (cairo_perf_report_t *report,
     if (name == NULL)
 	name = "stdin";
 
-    configuration = xmalloc (strlen (name) * sizeof (char) + 1);
-    strcpy (configuration, name);
+    configuration = xstrdup (name);
     baseName = basename (configuration);
-    report->configuration = xmalloc (strlen (baseName) * sizeof (char) + 1);
-    strcpy (report->configuration, baseName);
+    report->configuration = xstrdup (baseName);
     free (configuration);
 
     dot = strrchr (report->configuration, '.');
diff --git a/test/cairo-test.c b/test/cairo-test.c
index a5ef633..7dda8c2 100644
--- a/test/cairo-test.c
+++ b/test/cairo-test.c
@@ -105,11 +105,9 @@ static int cairo_test_timeout = 60;
 static char *
 _cairo_test_fixup_name (const char *original)
 {
-    int len = strlen (original);
     char *name, *s;
 
-    name = xmalloc (len + 1);
-    s = memcpy (name, original, len + 1);
+    s = name = xstrdup (original);
     while ((s = strchr (s, '_')) != NULL)
 	*s++ = '-';
 
@@ -505,7 +503,6 @@ cairo_test_get_reference_image (cairo_test_context_t *ctx,
 				cairo_bool_t flatten)
 {
     cairo_surface_t *surface;
-    int len;
 
     if (ctx->ref_name != NULL) {
 	if (strcmp (ctx->ref_name, filename) == 0)
@@ -525,10 +522,7 @@ cairo_test_get_reference_image (cairo_test_context_t *ctx,
     if (cairo_surface_status (surface))
 	return surface;
 
-    len = strlen (filename);
-    ctx->ref_name = xmalloc (len + 1);
-    memcpy (ctx->ref_name, filename, len + 1);
-
+    ctx->ref_name = xstrdup (filename);
     ctx->ref_image = surface;
     return _cairo_test_flatten_reference_image (ctx, flatten);
 }
-- 
1.7.5.4



More information about the cairo mailing list