mirror of
https://github.com/shadow-maint/shadow.git
synced 2026-01-26 14:03:17 +00:00
src/usermod.c: update_gshadow_file(): Reduce scope of local variable
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>
This commit is contained in:
parent
68d42a8fbe
commit
da77a82ecb
@ -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.
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user