]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/usermod.c: update_gshadow_file(): Reduce scope of local variable
authorAlejandro Colomar <alx@kernel.org>
Fri, 17 May 2024 00:19:46 +0000 (02:19 +0200)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Mon, 20 May 2024 07:37:01 +0000 (09:37 +0200)
After _every_ iteration, 'changed' is always 'false'.  We don't need to
have it outside of the loop.

See:

$ grepc update_gshadow_file . \
| grep -e changed -e goto -e continue -e break -e free_ngrp -e '{' -e '}' \
| pcre2grep -v -M '{\n\t*}';
{
bool               changed;
changed = false;
while ((sgrp = sgr_next ()) != NULL) {
if (!was_member && !was_admin && !is_member) {
continue;
}
if (was_admin && lflg) {
changed = true;
}
if (was_member) {
if ((!Gflg) || is_member) {
if (lflg) {
changed = true;
}
} else {
changed = true;
}
} else if (is_member) {
changed = true;
}
if (!changed)
goto free_nsgrp;
changed = false;
}
}

This was already true in the commit that introduced the code:

$ git show 45c6603cc:src/usermod.c \
| grepc update_gshadow \
| grep -e changed -e goto -e break -e continue -e '\<if\>' -e '{' -e '}' \
| pcre2grep -v -M '{\n\t*}';
{
int changed;
changed = 0;
while ((sgrp = sgr_next())) {
 * See if the user was a member of this group
 * See if the user was an administrator of this group
 * See if the user specified this group as one of their
if (!was_member && !was_admin && !is_member)
continue;
if (was_admin && lflg) {
changed = 1;
}
if (was_member && (!Gflg || is_member)) {
if (lflg) {
changed = 1;
}
} else if (was_member && Gflg && !is_member) {
changed = 1;
} else if (!was_member && Gflg && is_member) {
changed = 1;
}
if (!changed)
continue;
changed = 0;
}
}

Fixes: 45c6603cc86c ("[svn-upgrade] Integrating new upstream version, shadow (19990709)")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/usermod.c

index 30f47b8aada8ef08cf9accc8024ec05257076f5c..7b1e05818736399439ace2c4209bea21b50c69d8 100644 (file)
@@ -801,21 +801,21 @@ free_ngrp:
 static void
 update_gshadow_file(void)
 {
-       bool               changed;
        const struct sgrp  *sgrp;
 
-       changed = false;
-
        /*
         * Scan through the entire shadow group file looking for the groups
         * that the user is a member of.
         */
        while ((sgrp = sgr_next ()) != NULL) {
+               bool         changed;
                bool         is_member;
                bool         was_member;
                bool         was_admin;
                struct sgrp  *nsgrp;
 
+               changed = false;
+
                /*
                 * See if the user was a member of this group
                 */
@@ -924,8 +924,6 @@ update_gshadow_file(void)
                if (!changed)
                        goto free_nsgrp;
 
-               changed = false;
-
                /*
                 * Update the group entry to reflect the changes.
                 */