Skip to content

Simplify string handling #1048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ void sanitize_env (void)
if (!strprefix(*cur, *bad)) {
continue;
}
if (strchr (*cur, '/') == NULL) {
if (!strchr(*cur, '/'))
continue; /* OK */
}

for (move = cur; NULL != *move; move++) {
*move = *(move + 1);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/obscure.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <ctype.h>
#include <stdio.h>
#include <string.h>

#include "attr.h"
#include "prototypes.h"
Expand Down Expand Up @@ -66,9 +67,8 @@ static bool similar (/*@notnull@*/const char *old, /*@notnull@*/const char *new)
}

for (i = j = 0; ('\0' != new[i]) && ('\0' != old[i]); i++) {
if (strchr (new, old[i]) != NULL) {
if (strchr(new, old[i]))
j++;
}
}

if (i >= j * 2) {
Expand Down
2 changes: 1 addition & 1 deletion lib/setupenv.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void setup_env (struct passwd *info)
if (NULL == cp) {
/* not specified, use a minimal default */
addenv ((info->pw_uid == 0) ? "PATH=/sbin:/bin:/usr/sbin:/usr/bin" : "PATH=/bin:/usr/bin", NULL);
} else if (strchr (cp, '=')) {
} else if (strchr(cp, '=')) {
/* specified as name=value (PATH=...) */
addenv (cp, NULL);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/tcbfuncs.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static shadowtcb_status mkdir_leading (const char *name, uid_t uid)
shadow_progname, TCB_DIR, strerror (errno));
goto out_free_path;
}
while ((ind = strchr (ptr, '/'))) {
while (NULL != (ind = strchr(ptr, '/'))) {
stpcpy(ind, "");
dir = aprintf(TCB_DIR "/%s", path);
if (dir == NULL) {
Expand Down
8 changes: 4 additions & 4 deletions lib/utmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,12 @@ active_sessions_count(const char *name, unsigned long limit)
if (USER_PROCESS != ut->ut_type) {
continue;
}
if ('\0' == ut->ut_user[0]) {
if (strncmp(ut->ut_user, "", countof(ut->ut_user)) == 0)
continue;
}
if (strncmp (name, ut->ut_user, sizeof (ut->ut_user)) != 0) {

if (strncmp(ut->ut_user, name, countof(ut->ut_user)) != 0)
continue;
}

count++;
if (count > limit) {
break;
Expand Down
4 changes: 2 additions & 2 deletions src/chfn.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <getopt.h>

Expand Down Expand Up @@ -160,9 +161,8 @@ static bool may_change_field (int field)
cp = "frwh";
}

if (strchr (cp, field) != NULL) {
if (strchr(cp, field))
return true;
}

return false;
}
Expand Down
5 changes: 2 additions & 3 deletions src/chpasswd.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef USE_PAM
#include "pam_defs.h"
Expand Down Expand Up @@ -509,10 +510,8 @@ int main (int argc, char **argv)
if (feof (stdin) == 0) {
// Drop all remaining characters on this line.
while (fgets (buf, sizeof buf, stdin) != NULL) {
cp = strchr (buf, '\n');
if (cp != NULL) {
if (strchr(buf, '\n'))
break;
}
}

fprintf (stderr,
Expand Down
3 changes: 1 addition & 2 deletions src/login_nopam.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,8 @@ static bool from_match (char *tok, const char *string)
return true;
}
} else if (strcaseeq(tok, "LOCAL")) { /* LOCAL: no dots */
if (strchr (string, '.') == NULL) {
if (!strchr(string, '.'))
return true;
}
} else if ( (!streq(tok, "") && tok[strlen(tok) - 1] == '.') /* network */
&& strprefix(resolve_hostname(string), tok)) {
return true;
Expand Down
5 changes: 3 additions & 2 deletions src/logoutd.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <utmpx.h>
Expand Down Expand Up @@ -178,9 +179,9 @@ main(int argc, char **argv)
if (ut->ut_type != USER_PROCESS) {
continue;
}
if (ut->ut_user[0] == '\0') {
if (strncmp(ut->ut_user, "", countof(ut->ut_user)) == 0)
continue;
}

if (check_login (ut)) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/su.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ static void set_environment (struct passwd *pw)
cp = getdef_str ((pw->pw_uid == 0) ? "ENV_SUPATH" : "ENV_PATH");
if (NULL == cp) {
addenv ((pw->pw_uid == 0) ? "PATH=/sbin:/bin:/usr/sbin:/usr/bin" : "PATH=/bin:/usr/bin", NULL);
} else if (strchr (cp, '=') != NULL) {
} else if (strchr(cp, '=')) {
addenv (cp, NULL);
} else {
addenv ("PATH", cp);
Expand Down
Loading