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