Use strdup instead of strlen + malloc + strcpy Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
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;i<geom->num_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;
}