lib/, src/: Use streq() instead of its pattern

Except for the added (and sorted) includes, the removal of redundant
parentheses, a few cases that have been refactored for readability, and
a couple of non-string cases that I've left out of the change, this
patch can be approximated with the following semantic patch:

	$ cat ~/tmp/spatch/streq.sp
	@@
	expression s;
	@@

	- '\0' == *s
	+ streq(s, "")

	@@
	expression s;
	@@

	- '\0' == s[0]
	+ streq(s, "")

	@@
	expression s;
	@@

	- *s == '\0'
	+ streq(s, "")

	@@
	expression s;
	@@

	- s[0] == '\0'
	+ streq(s, "")

	$ find contrib/ lib* src/ -type f \
	| xargs spatch --in-place --sp-file ~/tmp/spatch/streq.sp;

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2024-12-09 20:54:42 -06:00
committed by Serge Hallyn
parent 8424d7c494
commit 7182d6402f
28 changed files with 88 additions and 69 deletions
+2 -1
View File
@@ -580,7 +580,8 @@ static void check_grp_file (int *errors, bool *changed)
*/
if ( (NULL != grp->gr_mem[0])
&& (NULL == grp->gr_mem[1])
&& ('\0' == grp->gr_mem[0][0])) {
&& streq(grp->gr_mem[0], ""))
{
grp->gr_mem[0] = NULL;
}
+3 -3
View File
@@ -661,7 +661,7 @@ int main (int argc, char **argv)
/* if we didn't get a user on the command line,
set it to NULL */
get_pam_user (&pam_user);
if ((NULL != pam_user) && ('\0' == pam_user[0])) {
if ((NULL != pam_user) && streq(pam_user, "")) {
retcode = pam_set_item (pamh, PAM_USER, NULL);
PAM_FAIL_CHECK;
}
@@ -838,7 +838,7 @@ int main (int argc, char **argv)
username = XMALLOC(max_size, char);
login_prompt(username, max_size);
if ('\0' == username[0]) {
if (streq(username, "")) {
/* Prompt for a new login */
free (username);
username = NULL;
@@ -963,7 +963,7 @@ int main (int argc, char **argv)
* guys won't see that the passwordless account exists at
* all). --marekm
*/
if (user_passwd[0] == '\0') {
if (streq(user_passwd, "")) {
pw_auth ("!", username, reason, NULL);
}
+14 -13
View File
@@ -29,7 +29,6 @@
#ifndef USE_PAM
#ident "$Id$"
#include "prototypes.h"
/*
* This module implements a simple but effective form of login access
* control based on login names and on host (or domain) names, internet
@@ -38,27 +37,29 @@
*
* Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
*/
#include <sys/types.h>
#include <stddef.h>
#include <stdio.h>
#include <syslog.h>
#include <arpa/inet.h> /* for inet_ntoa() */
#include <ctype.h>
#include <netdb.h>
#include <errno.h>
#include <grp.h>
#include <netdb.h>
#include <netinet/in.h>
#ifdef PRIMARY_GROUP_MATCH
#include <pwd.h>
#endif
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h> /* for inet_ntoa() */
#include <sys/types.h>
#include <syslog.h>
#include <unistd.h>
#include "prototypes.h"
#include "sizeof.h"
#include "string/strchr/strrspn.h"
#include "string/strcmp/streq.h"
#include "string/strtok/stpsep.h"
@@ -110,7 +111,7 @@ login_access(const char *user, const char *from)
continue; /* comment line */
}
stpcpy(strrspn(line, " \t"), "");
if (line[0] == '\0') { /* skip blank lines */
if (streq(line, "")) { /* skip blank lines */
continue;
}
p = line;
@@ -182,7 +183,7 @@ static char *myhostname (void)
{
static char name[MAXHOSTNAMELEN + 1] = "";
if (name[0] == '\0') {
if (streq(name, "")) {
gethostname (name, sizeof (name));
stpcpy(&name[MAXHOSTNAMELEN], "");
}
+3 -3
View File
@@ -150,7 +150,7 @@ static void check_perms (const struct group *grp,
spw_free (spwd);
}
if ((pwd->pw_passwd[0] == '\0') && (grp->gr_passwd[0] != '\0')) {
if (streq(pwd->pw_passwd, "") && (grp->gr_passwd[0] != '\0')) {
needspasswd = true;
}
@@ -188,8 +188,8 @@ static void check_perms (const struct group *grp,
goto failure;
}
if (grp->gr_passwd[0] == '\0' ||
!streq(cpasswd, grp->gr_passwd)) {
if (streq(grp->gr_passwd, "") ||
!streq(grp->gr_passwd, cpasswd)) {
#ifdef WITH_AUDIT
SNPRINTF(audit_buf, "authentication new-gid=%lu",
(unsigned long) grp->gr_gid);
+1 -1
View File
@@ -441,7 +441,7 @@ static /*@observer@*/const char *pw_status (const char *pass)
if (*pass == '*' || *pass == '!') {
return "L";
}
if (*pass == '\0') {
if (streq(pass, "")) {
return "NP";
}
return "P";
+2 -2
View File
@@ -862,7 +862,7 @@ static void process_flags (int argc, char **argv)
if (optind < argc) {
STRTCPY(name, argv[optind++]); /* use this login id */
}
if ('\0' == name[0]) { /* use default user */
if (streq(name, "")) { /* use default user */
struct passwd *root_pw = getpwnam ("root");
if ((NULL != root_pw) && (0 == root_pw->pw_uid)) {
(void) strcpy (name, "root");
@@ -1080,7 +1080,7 @@ int main (int argc, char **argv)
/*
* Set the default shell.
*/
if ((NULL == shellstr) || ('\0' == shellstr[0])) {
if ((NULL == shellstr) || streq(shellstr, "")) {
shellstr = SHELL;
}
+1 -1
View File
@@ -86,7 +86,7 @@ check_su_auth(const char *actual_id, const char *wanted_id, bool su_to_root)
stpcpy(strrspn(temp, " \t"), "");
p = stpspn(temp, " \t");
if (*p == '#' || *p == '\0')
if (*p == '#' || streq(p, ""))
continue;
to_users = strsep(&p, ":");
+2 -1
View File
@@ -27,6 +27,7 @@
/*@-exitarg@*/
#include "exitcodes.h"
#include "shadowlog.h"
#include "string/strcmp/streq.h"
#include "string/strdup/xstrdup.h"
@@ -153,7 +154,7 @@ main(int argc, char *argv[])
* it will work with standard getpass() (no NULL on EOF).
* --marekm
*/
if ((NULL == pass) || ('\0' == *pass)) {
if ((NULL == pass) || streq(pass, "")) {
erase_pass (pass);
(void) puts ("");
#ifdef TELINIT
+5 -5
View File
@@ -439,7 +439,7 @@ get_defaults(void)
* Default Skeleton information
*/
else if (streq(buf, DSKEL)) {
if ('\0' == *ccp)
if (streq(ccp, ""))
ccp = SKEL_DIR;
if (prefix[0]) {
@@ -456,7 +456,7 @@ get_defaults(void)
* Default Usr Skeleton information
*/
else if (streq(buf, DUSRSKEL)) {
if ('\0' == *ccp)
if (streq(ccp, ""))
ccp = USRSKELDIR;
if (prefix[0]) {
@@ -472,7 +472,7 @@ get_defaults(void)
* Create by default user mail spool or not ?
*/
else if (streq(buf, DCREATE_MAIL_SPOOL)) {
if (*ccp == '\0')
if (streq(ccp, ""))
ccp = "no";
def_create_mail_spool = xstrdup(ccp);
@@ -482,7 +482,7 @@ get_defaults(void)
* By default do we add the user to the lastlog and faillog databases ?
*/
else if (streq(buf, DLOG_INIT)) {
if (*ccp == '\0')
if (streq(ccp, ""))
ccp = def_log_init;
def_log_init = xstrdup(ccp);
@@ -770,7 +770,7 @@ static int get_groups (char *list)
user_groups[i++] = NULL;
}
if ('\0' == *list) {
if (streq(list, "")) {
return 0;
}
+2 -2
View File
@@ -1131,7 +1131,7 @@ int main (int argc, char **argv)
* Note: This is a best effort basis. The user may log in between,
* a cron job may be started on her behalf, etc.
*/
if ((prefix[0] == '\0') && !Rflg && user_busy (user_name, user_id) != 0) {
if (streq(prefix, "") && !Rflg && user_busy(user_name, user_id) != 0) {
if (!fflg) {
#ifdef WITH_AUDIT
audit_logger (AUDIT_DEL_USER, Prog,
@@ -1264,7 +1264,7 @@ int main (int argc, char **argv)
* Cancel any crontabs or at jobs. Have to do this before we remove
* the entry from /etc/passwd.
*/
if (prefix[0] == '\0')
if (streq(prefix, ""))
user_cancel (user_name);
close_files ();
+2 -2
View File
@@ -227,7 +227,7 @@ static int get_groups (char *list)
*/
user_groups[0] = NULL;
if ('\0' == *list) {
if (streq(list, "")) {
return 0;
}
@@ -2186,7 +2186,7 @@ int main (int argc, char **argv)
* be changed while the user is logged in.
* Note: no need to check if a prefix is specified...
*/
if ( (prefix[0] == '\0') && (uflg || lflg || dflg
if (streq(prefix, "") && (uflg || lflg || dflg
#ifdef ENABLE_SUBIDS
|| Vflg || Wflg
#endif /* ENABLE_SUBIDS */