summaryrefslogtreecommitdiffstats
path: root/lib/stringlist.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/stringlist.c')
-rw-r--r--lib/stringlist.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/stringlist.c b/lib/stringlist.c
index a8ff97964f..c8b835ed09 100644
--- a/lib/stringlist.c
+++ b/lib/stringlist.c
@@ -16,9 +16,8 @@ int string_list_add(struct string_list *sl, char *str)
{
struct string_list *new;
- new = xmalloc(sizeof(struct string_list) + strlen(str) + 1);
-
- strcpy(new->str, str);
+ new = xmalloc(sizeof(*new));
+ new->str = xstrdup(str);
list_add_tail(&new->list, &sl->list);
@@ -29,9 +28,8 @@ int string_list_add_sorted(struct string_list *sl, char *str)
{
struct string_list *new;
- new = xmalloc(sizeof(struct string_list) + strlen(str) + 1);
-
- strcpy(new->str, str);
+ new = xmalloc(sizeof(*new));
+ new->str = xstrdup(str);
list_add_sort(&new->list, &sl->list, string_list_compare);