From: Alejandro Colomar Date: Thu, 14 Nov 2024 18:29:04 +0000 (+0100) Subject: lib/addgrps.c: add_groups(): Split variable to avoid sign-mismatch diagnostics X-Git-Tag: 4.17.3~39 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=9476033aa9aeada0047efc086d1ee22622069c50;p=thirdparty%2Fshadow.git lib/addgrps.c: add_groups(): Split variable to avoid sign-mismatch diagnostics Reviewed-by: Serge Hallyn Signed-off-by: Alejandro Colomar --- diff --git a/lib/addgrps.c b/lib/addgrps.c index 70ccd5a45..88a9710bc 100644 --- a/lib/addgrps.c +++ b/lib/addgrps.c @@ -38,7 +38,8 @@ add_groups(const char *list) char *g, *p; char buf[1024]; FILE *shadow_logfd = log_get_logfd(); - size_t ngroups; + size_t n; + ssize_t n0; if (strlen (list) >= sizeof (buf)) { errno = EINVAL; @@ -46,18 +47,19 @@ add_groups(const char *list) } strcpy (buf, list); - ngroups = getgroups(0, NULL); - if (ngroups == -1) + n0 = getgroups(0, NULL); + if (n0 == -1) return -1; - grouplist = MALLOC(ngroups, GETGROUPS_T); + grouplist = MALLOC(n0, GETGROUPS_T); if (grouplist == NULL) return -1; - ngroups = getgroups(ngroups, grouplist); - if (ngroups == -1) + n0 = getgroups(n0, grouplist); + if (n0 == -1) goto free_gids; + n = n0; p = buf; while (NULL != (g = strsep(&p, ",:"))) { struct group *grp; @@ -68,14 +70,14 @@ add_groups(const char *list) continue; } - grouplist = REALLOCF(grouplist, ngroups + 1, GETGROUPS_T); + grouplist = REALLOCF(grouplist, n + 1, GETGROUPS_T); if (grouplist == NULL) return -1; - LSEARCH(&grp->gr_gid, grouplist, &ngroups); + LSEARCH(&grp->gr_gid, grouplist, &n); } - if (setgroups(ngroups, grouplist) == -1) { + if (setgroups(n, grouplist) == -1) { fprintf(shadow_logfd, "setgroups: %s\n", strerror(errno)); goto free_gids; }