From f424251244d1509c5bf5e8779a4820bd76f18473 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Wed, 29 Feb 2012 20:12:17 +0200 Subject: [PATCH] Use strdup instead of strlen + malloc + strcpy Signed-off-by: Ran Benita --- src/galloc.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/galloc.c b/src/galloc.c index cb0b0f8..116f3c3 100644 --- a/src/galloc.c +++ b/src/galloc.c @@ -463,9 +463,7 @@ register struct xkb_property * prop; for (i=0,prop=geom->properties;inum_properties;i++,prop++) { if ((prop->name)&&(strcmp(name,prop->name)==0)) { free(prop->value); - prop->value= (char *)malloc(strlen(value)+1); - if (prop->value) - strcpy(prop->value,value); + prop->value = strdup(value); return prop; } } @@ -474,17 +472,15 @@ register struct xkb_property * prop; return NULL; } prop= &geom->properties[geom->num_properties]; - prop->name= (char *)malloc(strlen(name)+1); - if (!name) + prop->name = strdup(name); + if (!prop->name) return NULL; - strcpy(prop->name,name); - prop->value= (char *)malloc(strlen(value)+1); - if (!value) { + prop->value = strdup(value); + if (!prop->value) { free(prop->name); prop->name= NULL; return NULL; } - strcpy(prop->value,value); geom->num_properties++; return prop; } @@ -509,10 +505,9 @@ register struct xkb_color * color; } color= &geom->colors[geom->num_colors]; color->pixel= pixel; - color->spec= (char *)malloc(strlen(spec)+1); + color->spec = strdup(spec); if (!color->spec) return NULL; - strcpy(color->spec,spec); geom->num_colors++; return color; } -- 2.7.4