Use reallocarrayf() instead of its pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2023-02-04 22:52:13 +01:00
committed by Serge Hallyn
parent 191f04f7dc
commit 190a702225

View File

@@ -29,7 +29,7 @@
*/ */
int add_groups (const char *list) int add_groups (const char *list)
{ {
GETGROUPS_T *grouplist, *tmp; GETGROUPS_T *grouplist;
size_t i; size_t i;
int ngroups; int ngroups;
bool added; bool added;
@@ -88,14 +88,12 @@ int add_groups (const char *list)
fputs (_("Warning: too many groups\n"), shadow_logfd); fputs (_("Warning: too many groups\n"), shadow_logfd);
break; break;
} }
tmp = (gid_t *) reallocarray (grouplist, (size_t)ngroups + 1, sizeof (GETGROUPS_T)); grouplist = (gid_t *) reallocarrayf (grouplist, (size_t)ngroups + 1, sizeof (GETGROUPS_T));
if (NULL == tmp) { if (grouplist == NULL) {
free (grouplist);
return -1; return -1;
} }
tmp[ngroups] = grp->gr_gid; grouplist[ngroups] = grp->gr_gid;
ngroups++; ngroups++;
grouplist = tmp;
added = true; added = true;
} }