From: Alejandro Colomar Date: Thu, 14 Nov 2024 17:43:40 +0000 (+0100) Subject: lib/, src/: Use LSEARCH() instead of its pattern X-Git-Tag: 4.17.3~40 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=90cd8428c7cabab1369dc7176175ff5c79e67f0d;p=thirdparty%2Fshadow.git lib/, src/: Use LSEARCH() instead of its pattern Reviewed-by: Serge Hallyn Signed-off-by: Alejandro Colomar --- diff --git a/lib/addgrps.c b/lib/addgrps.c index 630bff8c6..70ccd5a45 100644 --- a/lib/addgrps.c +++ b/lib/addgrps.c @@ -20,7 +20,7 @@ #include "alloc/malloc.h" #include "alloc/reallocf.h" -#include "search/l/lfind.h" +#include "search/l/lsearch.h" #include "shadowlog.h" #ident "$Id$" @@ -35,10 +35,10 @@ int add_groups(const char *list) { GETGROUPS_T *grouplist; - int ngroups; char *g, *p; char buf[1024]; FILE *shadow_logfd = log_get_logfd(); + size_t ngroups; if (strlen (list) >= sizeof (buf)) { errno = EINVAL; @@ -72,11 +72,7 @@ add_groups(const char *list) if (grouplist == NULL) return -1; - if (LFIND(&grp->gr_gid, grouplist, ngroups) != NULL) - continue; - - grouplist[ngroups] = grp->gr_gid; - ngroups++; + LSEARCH(&grp->gr_gid, grouplist, &ngroups); } if (setgroups(ngroups, grouplist) == -1) { diff --git a/src/newgrp.c b/src/newgrp.c index 2b73ae01a..ada65fb81 100644 --- a/src/newgrp.c +++ b/src/newgrp.c @@ -25,6 +25,7 @@ #include "getdef.h" #include "prototypes.h" #include "search/l/lfind.h" +#include "search/l/lsearch.h" #include "shadowlog.h" #include "string/sprintf/snprintf.h" #include "string/strcmp/streq.h" @@ -38,7 +39,7 @@ static const char *Prog; extern char **newenvp; -static int ngroups; +static size_t ngroups; static /*@null@*/ /*@only@*/GETGROUPS_T *grouplist; static bool is_newgrp; @@ -682,9 +683,7 @@ fail_gg: */ grouplist = XREALLOC(grouplist, ngroups + 1, GETGROUPS_T); - if (LFIND(&gid, grouplist, ngroups) == NULL) { - grouplist[ngroups++] = gid; - } + LSEARCH(&gid, grouplist, &ngroups); if (setgroups(ngroups, grouplist) == -1) perror("setgroups");