]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/gshadow.c: Move zeroing to within build_list()
authorAlejandro Colomar <alx@kernel.org>
Tue, 5 Nov 2024 13:56:14 +0000 (14:56 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 6 Dec 2024 03:20:59 +0000 (21:20 -0600)
This makes build_list() less dependent on the context.
It starts from clean, whatever the state before the call was.
I was having a hard time understanding the reallocation,
until I saw that we were zeroing everything right before the call.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/gshadow.c

index 15e1ac977c40dc0dd246fdfb9d83126e6ade6f6d..c919270142b063dd7c8552111ecbc0290c63031e 100644 (file)
@@ -40,7 +40,10 @@ static /*@null@*/char **
 build_list(char *s, char ***lp, size_t *np)
 {
        char    **l;
-       size_t  n = *np;
+       size_t  n;
+
+       *lp = NULL;
+       n = 0;
 
        while (s != NULL && *s != '\0') {
                l = XREALLOC(*lp, n + 1, char *);
@@ -117,12 +120,8 @@ sgetsgent(const char *string)
        sgroup.sg_name = fields[0];
        sgroup.sg_passwd = fields[1];
 
-       nadmins = 0;
        free (admins);
-       admins = NULL;
-       nmembers = 0;
        free (members);
-       members = NULL;
 
        sgroup.sg_adm = build_list (fields[2], &admins, &nadmins);
        sgroup.sg_mem = build_list (fields[3], &members, &nmembers);