From: Alejandro Colomar Date: Sat, 8 Feb 2025 12:00:22 +0000 (+0100) Subject: lib/list.c: Use strsep2ls() instead of its pattern X-Git-Tag: 4.18.0-rc1~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cadd9c355ebdb79e38cfa893a952d3a8be3e42c2;p=thirdparty%2Fshadow.git lib/list.c: Use strsep2ls() instead of its pattern Signed-off-by: Alejandro Colomar --- diff --git a/lib/list.c b/lib/list.c index 27aa02565..25735d72f 100644 --- a/lib/list.c +++ b/lib/list.c @@ -18,6 +18,7 @@ #include "string/strchr/strchrcnt.h" #include "string/strcmp/streq.h" #include "string/strdup/xstrdup.h" +#include "string/strtok/strsep2ls.h" /* @@ -186,9 +187,7 @@ comma_to_list(const char *comma) { char *members; char **array; - int i; - char *cp; - char *cp2; + size_t n; assert (NULL != comma); @@ -203,7 +202,8 @@ comma_to_list(const char *comma) * n: number of delimiters + last element + NULL */ - array = XMALLOC(strchrcnt(members, ',') + 2, char *); + n = strchrcnt(members, ',') + 2; + array = XMALLOC(n, char *); /* * Empty list is special - 0 members, not 1 empty member. --marekm @@ -215,18 +215,7 @@ comma_to_list(const char *comma) return array; } - /* - * Now go walk that list all over again, this time building the - * array of pointers. - */ - - for (cp = members, i = 0; cp != NULL; i++) - array[i] = strsep(&cp, ","); - array[i] = NULL; - - /* - * Return the new array of pointers - */ + strsep2ls(members, ",", n, array); return array; }