From ecce8f098d1e65be873f33f8c71d2d5023f97916 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 5 Nov 2024 14:56:14 +0100 Subject: [PATCH] lib/gshadow.c: Move zeroing to within build_list() 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 --- lib/gshadow.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/gshadow.c b/lib/gshadow.c index 15e1ac97..c9192701 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -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);