diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2012-04-19 10:34:11 +0800 |
---|---|---|
committer | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2012-04-30 20:22:23 +0800 |
commit | 34faa2e7ca95f8f7f4a235bb5b25fd604612f140 (patch) | |
tree | 250440f42c5b6b2baeb2ba760ef09bb573a40f2e /lib | |
parent | 6b489256ee1358973d536e723c77c2483e6b9f5b (diff) | |
download | barebox-34faa2e7ca95f8f7f4a235bb5b25fd604612f140.tar.gz barebox-34faa2e7ca95f8f7f4a235bb5b25fd604612f140.tar.xz |
stringlist: use seperately allocated string
Allocate the string in string list seperately instead of
embedding a zero length string into struct stringlist.
Besides looking cleaner this allows us to implement a
string_list_asprintf.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/stringlist.c | 10 |
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); |