From: Alejandro Colomar Date: Tue, 5 Nov 2024 13:56:14 +0000 (+0100) Subject: lib/gshadow.c: Move zeroing to within build_list() X-Git-Tag: 4.17.0-rc1~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ecce8f098d1e65be873f33f8c71d2d5023f97916;p=thirdparty%2Fshadow.git 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 --- diff --git a/lib/gshadow.c b/lib/gshadow.c index 15e1ac977..c91927014 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);