]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/: Use strsep2arr() instead of its pattern
authorAlejandro Colomar <alx@kernel.org>
Fri, 6 Dec 2024 23:51:14 +0000 (00:51 +0100)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Sat, 7 Jun 2025 14:52:03 +0000 (16:52 +0200)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/sgetspent.c

index 8a19e8d82532993d1bf79b8c36c4f6d63aa1de53..2c620aef60be39b7f52dc75f5806e592c7018d81 100644 (file)
 #include "defines.h"
 #include "prototypes.h"
 #include "shadowlog_internal.h"
+#include "sizeof.h"
 #include "string/strcmp/streq.h"
 #include "string/strtok/stpsep.h"
+#include "string/strtok/strsep2arr.h"
 
 
 #define        FIELDS  9
@@ -43,8 +45,7 @@ sgetspent(const char *s)
        static struct spwd spwd;
 
        char *fields[FIELDS];
-       char *cp;
-       int i;
+       size_t  i;
 
        free(dup);
        dup = strdup(s);
@@ -53,18 +54,10 @@ sgetspent(const char *s)
 
        stpsep(dup, "\n");
 
-       /*
-        * Tokenize the string into colon separated fields.  Allow up to
-        * FIELDS different fields.
-        */
-
-       for (cp = dup, i = 0; cp != NULL && i < FIELDS; i++)
-               fields[i] = strsep(&cp, ":");
-
-       if (i == (FIELDS - 1))
+       i = strsep2arr(dup, ":", countof(fields), fields);
+       if (i == countof(fields) - 1)
                fields[i++] = "";
-
-       if (cp != NULL || (i != FIELDS && i != OFIELDS))
+       if (i != countof(fields) && i != OFIELDS)
                return NULL;
 
        /*