Skip to content

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

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

Merged
merged 2 commits into from
Dec 10, 2024

Conversation

alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Dec 6, 2024

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 semantic patches (see commit messages).


Revisions:

v2
  • Fix typo in commit message.
  • Add patch 2 (!streq()).
$ git range-diff master gh/streq_empty streq_empty 
1:  a7d14373 ! 1:  7e329852 lib/, src/: Use streq() instead of its pattern
    @@ Commit message
                 + streq(s, "")
     
                 $ find contrib/ lib* src/ -type f \
    -            | xargs spatch --sp-file --in-place ~/tmp/spatch/streq.sp;
    +            | xargs spatch --in-place --sp-file ~/tmp/spatch/streq.sp;
     
         Signed-off-by: Alejandro Colomar <[email protected]>
     
-:  -------- > 2:  20460298 lib/, src/: Use !streq() instead of its pattern
v3
  • Expand patch 3 thanks to spatch(1).
$ git range-diff --creation-factor=99 master gh/streq_empty streq_empty 
1:  7e329852 = 1:  7e329852 lib/, src/: Use streq() instead of its pattern
2:  20460298 ! 2:  eb9c40c2 lib/, src/: Use !streq() instead of its pattern
    @@ Metadata
      ## Commit message ##
         lib/, src/: Use !streq() instead of its pattern
     
    +    Except for the added (and sorted) includes, the removal of redundant
    +    parentheses, and a few non-string cases that I've left out of the
    +    change, this patch can be approximated with the following semantic
    +    patch:
    +
    +            $ cat ~/tmp/spatch/strneq.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/strneq.sp;
    +
         Signed-off-by: Alejandro Colomar <[email protected]>
     
    + ## lib/chkname.c ##
    +@@
    + 
    + #include "defines.h"
    + #include "chkname.h"
    ++#include "string/strcmp/streq.h"
    + 
    + 
    + int allow_bad_names = false;
    +@@ lib/chkname.c: is_valid_name(const char *name)
    + 
    +   numeric = isdigit(*name);
    + 
    +-  while ('\0' != *++name) {
    ++  while (!streq(++name, "")) {
    +           if (!((*name >= 'a' && *name <= 'z') ||
    +                 (*name >= 'A' && *name <= 'Z') ||
    +                 (*name >= '0' && *name <= '9') ||
    +
    + ## lib/fields.c ##
    +@@
    + #include "prototypes.h"
    + #include "string/strchr/stpspn.h"
    + #include "string/strchr/strrspn.h"
    ++#include "string/strcmp/streq.h"
    + #include "string/strtok/stpsep.h"
    + 
    + 
    +@@ lib/fields.c: int valid_field (const char *field, const char *illegal)
    +   }
    + 
    +   /* Search if there are non-printable or control characters */
    +-  for (cp = field; '\0' != *cp; cp++) {
    ++  for (cp = field; !streq(cp, ""); cp++) {
    +           unsigned char c = *cp;
    +           if (!isprint (c)) {
    +                   err = 1;
    +@@ lib/fields.c: change_field(char *buf, size_t maxsize, const char *prompt)
    +   if (stpsep(newf, "\n") == NULL)
    +           return;
    + 
    +-  if ('\0' != newf[0]) {
    ++  if (!streq(newf, "")) {
    +           /*
    +            * Remove leading and trailing whitespace.  This also
    +            * makes it possible to change the field to empty, by
    +
    + ## lib/fputsx.c ##
    +@@
    + 
    + #include "defines.h"
    + #include "prototypes.h"
    +-
    +-#ident "$Id$"
    ++#include "string/strcmp/streq.h"
    + 
    + 
    + /*@null@*/char *
    +@@ lib/fputsx.c: int fputsx (const char *s, FILE * stream)
    + {
    +   int i;
    + 
    +-  for (i = 0; '\0' != *s; i++, s++) {
    ++  for (i = 0; !streq(s, ""); i++, s++) {
    +           if (putc (*s, stream) == EOF) {
    +                   return EOF;
    +           }
    +
    + ## lib/getdate.y ##
    +@@ lib/getdate.y: static int LookupWord (char *buff)
    +   bool abbrev;
    + 
    +   /* Make it lowercase. */
    +-  for (p = buff; '\0' != *p; p++)
    ++  for (p = buff; !streq(p, ""); p++)
    +     if (isupper (*p))
    +       *p = tolower (*p);
    + 
    +@@ lib/getdate.y: static int LookupWord (char *buff)
    +     }
    + 
    +   /* Drop out any periods and try the timezone table again. */
    +-  for (i = 0, p = q = buff; '\0' != *q; q++)
    ++  for (i = 0, p = q = buff; !streq(q, ""); q++)
    +     if (*q != '.')
    +       *p++ = *q;
    +     else
    +
    + ## lib/gshadow.c ##
    +@@ lib/gshadow.c: static /*@null@*/char **build_list (char *s, char **list[], size_t * nlist)
    +   char **ptr = *list;
    +   size_t nelem = *nlist, size;
    + 
    +-  while (s != NULL && *s != '\0') {
    ++  while (s != NULL && !streq(s, "")) {
    +           ptr = XREALLOC(*list, nelem + 1, char *);
    +           ptr[nelem] = strsep(&s, ",");
    +           nelem++;
    +
    + ## lib/limits.c ##
    +@@ lib/limits.c: static int do_user_limits (const char *buf, const char *name)
    +           pp = "A- C- D- F- I- L- M- N- O- P- R- S- T- U-";
    +   }
    + 
    +-  while ('\0' != *pp) {
    ++  while (!streq(pp, "")) {
    +           switch (*pp++) {
    +           case 'a':
    +           case 'A':
    +
    + ## lib/myname.c ##
    +@@
    + 
    + #ident "$Id$"
    + 
    +-#include "defines.h"
    + #include <pwd.h>
    ++
    ++#include "defines.h"
    + #include "prototypes.h"
    ++#include "string/strcmp/streq.h"
    ++
    ++
    + /*@null@*/ /*@only@*/struct passwd *get_my_pwent (void)
    + {
    +   struct passwd *pw;
    +@@
    +    * XXX - when running from su, will return the current user (not
    +    * the original user, like getlogin() does).  Does this matter?
    +    */
    +-  if ((NULL != cp) && ('\0' != *cp)) {
    ++  if ((NULL != cp) && !streq(cp, "")) {
    +           pw = xgetpwnam (cp);
    +           if ((NULL != pw) && (pw->pw_uid == ruid)) {
    +                   return pw;
    +
    + ## lib/nss.c ##
    +@@ lib/nss.c: nss_init(const char *nsswitch_path) {
    +                   continue;
    +           p = &line[6];
    +           p = stpspn(p, " \t\n");
    +-          if (*p != '\0')
    ++          if (!streq(p, ""))
    +                   break;
    +           p = NULL;
    +   }
    +
    + ## lib/obscure.c ##
    +@@ lib/obscure.c: static char *str_lower (/*@returned@*/char *string)
    + {
    +   char *cp;
    + 
    +-  for (cp = string; '\0' != *cp; cp++) {
    ++  for (cp = string; !streq(cp, ""); cp++) {
    +           *cp = tolower (*cp);
    +   }
    +   return string;
    +
      ## lib/port.c ##
    +@@ lib/port.c: static int portcmp (const char *pattern, const char *port)
    + {
    +   const char *orig = port;
    + 
    +-  while (('\0' != *pattern) && (*pattern == *port)) {
    ++  while (!streq(pattern, "") && (*pattern == *port)) {
    +           pattern++;
    +           port++;
    +   }
     @@ lib/port.c: next:
         * Get the next comma separated entry
         */
    @@ lib/port.c: next:
                /*
                 * Start off with no days of the week
     
    + ## lib/strtoday.c ##
    +@@ lib/strtoday.c: long strtoday (const char *str)
    +           s++;
    +   }
    +   s = stpspn(s, " ");
    +-  while (isnum && ('\0' != *s)) {
    ++  while (isnum && !streq(s, "")) {
    +           if (!isdigit (*s)) {
    +                   isnum = false;
    +           }
    +
    + ## lib/ttytype.c ##
    +@@ lib/ttytype.c: void ttytype (const char *line)
    +                   break;
    +           }
    +   }
    +-  if ((feof (fp) == 0) && (ferror (fp) == 0) && (type[0] != '\0')) {
    ++  if ((feof(fp) == 0) && (ferror(fp) == 0) && !streq(type, "")) {
    +           addenv ("TERM", type);
    +   }
    + 
    +
    + ## lib/utmp.c ##
    +@@ lib/utmp.c: prepare_utmp(const char *name, const char *line, const char *host,
    + 
    + 
    + 
    +-  if (NULL != host && '\0' != host[0])
    ++  if (NULL != host && !streq(host, ""))
    +           hostname = xstrdup(host);
    + #if defined(HAVE_STRUCT_UTMPX_UT_HOST)
    +   else if (NULL != ut && '\0' != ut->ut_host[0])
    +
    + ## src/chfn.c ##
    +@@ src/chfn.c: static char *copy_field (char *in, char *out, char *extra)
    +                   break;
    + 
    +           if (NULL != extra) {
    +-                  if ('\0' != extra[0]) {
    ++                  if (!streq(extra, "")) {
    +                           strcat (extra, ",");
    +                   }
    + 
    +@@ src/chfn.c: static void get_old_fields (const char *gecos)
    +    * Anything left over is "slop".
    +    */
    +   if ((NULL != cp) && !oflg) {
    +-          if ('\0' != slop[0]) {
    ++          if (!streq(slop, "")) {
    +                   strcat (slop, ",");
    +           }
    + 
    +@@ src/chfn.c: int main (int argc, char **argv)
    +   }
    +   SNPRINTF(new_gecos, "%s,%s,%s,%s%s%s",
    +            fullnm, roomno, workph, homeph,
    +-           ('\0' != slop[0]) ? "," : "", slop);
    ++           (!streq(slop, "")) ? "," : "", slop);
    + 
    +   /* Rewrite the user's gecos in the passwd file */
    +   update_gecos (user, new_gecos);
    +
    + ## src/gpasswd.c ##
    +@@ src/gpasswd.c: static bool is_valid_user_list (const char *users)
    + 
    +   tmpusers = dup = xstrdup(users);
    + 
    +-  while (NULL != tmpusers && '\0' != *tmpusers) {
    ++  while (NULL != tmpusers && !streq(tmpusers, "")) {
    +           const char  *u;
    + 
    +           u = strsep(&tmpusers, ",");
    +
    + ## src/login.c ##
    +@@ src/login.c: static /*@observer@*/const char *get_failent_user (/*@returned@*/const char *use
    +   const char *failent_user = "UNKNOWN";
    +   bool log_unkfail_enab = getdef_bool("LOG_UNKFAIL_ENAB");
    + 
    +-  if ((NULL != user) && ('\0' != user[0])) {
    ++  if ((NULL != user) && !streq(user, "")) {
    +           if (   log_unkfail_enab
    +               || (getpwnam (user) != NULL)) {
    +                   failent_user = user;
    +@@ src/login.c: int main (int argc, char **argv)
    + 
    +   if (hflg) {
    +           cp = hostname;
    +-  } else if ((host != NULL) && (host[0] != '\0')) {
    ++  } else if ((host != NULL) && !streq(host, "")) {
    +           cp = host;
    +   } else {
    +           cp = "";
    +   }
    + 
    +-  if ('\0' != *cp) {
    ++  if (!streq(cp, "")) {
    +           SNPRINTF(fromhost, " on '%.100s' from '%.200s'", tty, cp);
    +   } else {
    +           SNPRINTF(fromhost, " on '%.100s'", tty);
    +@@ src/login.c: int main (int argc, char **argv)
    +                   failed = true;
    +           }
    +           if (   !failed
    +-              && !login_access (username, ('\0' != *hostname) ? hostname : tty)) {
    ++              && !login_access(username, (!streq(hostname, "")) ? hostname : tty)) {
    +                   SYSLOG ((LOG_WARN, "LOGIN '%s' REFUSED %s",
    +                            username, fromhost));
    +                   failed = true;
    +
      ## src/login_nopam.c ##
     @@ src/login_nopam.c: static bool from_match (const char *tok, const char *string)
                if (strchr (string, '.') == NULL) {
                        return true;
                }
     -  } else if (   (tok[0] != '\0' && tok[(tok_len = strlen (tok)) - 1] == '.') /* network */
    -+  } else if (   (!streq(tok != '\0') && tok[(tok_len = strlen (tok)) - 1] == '.') /* network */
    ++  } else if (   (!streq(tok, "") && tok[(tok_len = strlen(tok)) - 1] == '.') /* network */
                   && (strncmp (tok, resolve_hostname (string), tok_len) == 0)) {
                return true;
        }
    @@ src/newgrp.c: static void check_perms (const struct group *grp,
                needspasswd = true;
        }
      
    +@@ src/newgrp.c: int main (int argc, char **argv)
    +   cp = getenv ("SHELL");
    +   if (!initflag && (NULL != cp)) {
    +           prog = cp;
    +-  } else if ((NULL != pwd->pw_shell) && ('\0' != pwd->pw_shell[0])) {
    ++  } else if ((NULL != pwd->pw_shell) && !streq(pwd->pw_shell, "")) {
    +           prog = pwd->pw_shell;
    +   } else {
    +           prog = SHELL;
    +
    + ## src/newusers.c ##
    +@@ src/newusers.c: static int add_group (const char *name, const char *gid, gid_t *ngid, uid_t uid)
    +   /*
    +    * Now I have all of the fields required to create the new group.
    +    */
    +-  if (('\0' != gid[0]) && (!isdigit (gid[0]))) {
    ++  if (!streq(gid, "") && (!isdigit(gid[0]))) {
    +           grent.gr_name = xstrdup (gid);
    +   } else {
    +           grent.gr_name = xstrdup (name);
    +@@ src/newusers.c: static int get_user_id (const char *uid, uid_t *nuid) {
    +                   return -1;
    +           }
    +   } else {
    +-          if ('\0' != uid[0]) {
    ++          if (!streq(uid, "")) {
    +                   const struct passwd *pwd;
    +                   /* local, no need for xgetpwnam */
    +                   pwd = getpwnam (uid);
    +@@ src/newusers.c: int main (int argc, char **argv)
    +                            Prog, line);
    +                   fail_exit (EXIT_FAILURE);
    +           }
    +-          if ('\0' != fields[4][0]) {
    ++          if (!streq(fields[4], "")) {
    +                   newpw.pw_gecos = fields[4];
    +           }
    + 
    +-          if ('\0' != fields[5][0]) {
    ++          if (!streq(fields[5], "")) {
    +                   newpw.pw_dir = fields[5];
    +           }
    + 
    +-          if ('\0' != fields[6][0]) {
    ++          if (!streq(fields[6], "")) {
    +                   newpw.pw_shell = fields[6];
    +           }
    + 
    +-          if (   ('\0' != fields[5][0])
    ++          if (   !streq(fields[5], "")
    +               && (access (newpw.pw_dir, F_OK) != 0)) {
    + /* FIXME: should check for directory */
    +                   mode_t mode = getdef_num ("HOME_MODE",
    +
    + ## src/passwd.c ##
    +@@ src/passwd.c: static int new_password (const struct passwd *pw)
    +    * password.
    +    */
    + 
    +-  if (!amroot && ('\0' != crypt_passwd[0])) {
    ++  if (!amroot && !streq(crypt_passwd, "")) {
    +           clear = agetpass (_("Old password: "));
    +           if (NULL == clear) {
    +                   return -1;
    +
    + ## src/pwck.c ##
    +@@ src/pwck.c: static void check_pw_file (int *errors, bool *changed)
    +            * Make sure the login shell is executable
    +            */
    +           if (   !quiet
    +-              && ('\0' != pwd->pw_shell[0])
    ++              && !streq(pwd->pw_shell, "")
    +               && (access (pwd->pw_shell, F_OK) != 0)) {
    + 
    +                   /*
    +
    + ## src/su.c ##
    +@@ src/su.c: int main (int argc, char **argv)
    +   sulog (caller_tty, true, caller_name, name);    /* save SU information */
    +   if (getdef_bool ("SYSLOG_SU_ENAB")) {
    +           SYSLOG ((LOG_INFO, "+ %s %s:%s", caller_tty,
    +-                   ('\0' != caller_name[0]) ? caller_name : "???",
    +-                   ('\0' != name[0]) ? name : "???"));
    ++                   (!streq(caller_name, "")) ? caller_name : "???",
    ++                   (!streq(name, "")) ? name : "???"));
    +   }
    + 
    + #ifdef USE_PAM
    +@@ src/su.c: int main (int argc, char **argv)
    +                           AUDIT_USER_ROLE_CHANGE,
    +                           NULL,    /* Prog. name */
    +                           "su",
    +-                          ('\0' != caller_name[0]) ? caller_name : "???",
    ++                          (!streq(caller_name, "")) ? caller_name : "???",
    +                           AUDIT_NO_ID,
    +                           "localhost",
    +                           NULL,    /* addr */
    +
    + ## src/useradd.c ##
    +@@ src/useradd.c: static bool
    +     Uflg = false;         /* create a group having the same name as the user */
    + 
    + #ifdef WITH_SELINUX
    +-#define Zflg ('\0' != *user_selinux)
    ++#define Zflg  (!streq(user_selinux, ""))
    + #endif                            /* WITH_SELINUX */
    + 
    + static bool home_added = false;
    +@@ src/useradd.c: static void process_flags (int argc, char **argv)
    +                           Dflg = true;
    +                           break;
    +                   case 'e':
    +-                          if ('\0' != *optarg) {
    ++                          if (!streq(optarg, "")) {
    +                                   user_expire = strtoday (optarg);
    +                                   if (user_expire < -1) {
    +                                           fprintf (stderr,
    +@@ src/useradd.c: static void process_flags (int argc, char **argv)
    +                           break;
    +                   case 's':
    +                           if (   ( !VALID (optarg) )
    +-                              || (   ('\0' != optarg[0])
    ++                              || (   !streq(optarg, "")
    +                                   && ('/'  != optarg[0])
    +                                   && ('*'  != optarg[0]) )) {
    +                                   fprintf (stderr,
    +@@ src/useradd.c: static void process_flags (int argc, char **argv)
    +                                            Prog, optarg);
    +                                   exit (E_BAD_ARG);
    +                           }
    +-                          if (    '\0' != optarg[0]
    ++                          if (!streq(optarg, "")
    +                                && '*'  != optarg[0]
    +                                && !streq(optarg, "/sbin/nologin")
    +                                && (   stat(optarg, &st) != 0
    +
    + ## src/usermod.c ##
    +@@ src/usermod.c: process_flags(int argc, char **argv)
    +                           break;
    +                   case 's':
    +                           if (   ( !VALID (optarg) )
    +-                              || (   ('\0' != optarg[0])
    ++                              || (   !streq(optarg, "")
    +                                   && ('/'  != optarg[0])
    +                                   && ('*'  != optarg[0]) )) {
    +                                   fprintf (stderr,
    +@@ src/usermod.c: process_flags(int argc, char **argv)
    +                                            Prog, optarg);
    +                                   exit (E_BAD_ARG);
    +                           }
    +-                          if (    '\0' != optarg[0]
    ++                          if (!streq(optarg, "")
    +                                && '*'  != optarg[0]
    +                                && !streq(optarg, "/sbin/nologin")
    +                                && (   stat(optarg, &st) != 0
    +@@ src/usermod.c: int main (int argc, char **argv)
    + 
    + #ifdef WITH_SELINUX
    +   if (Zflg) {
    +-          if ('\0' != *user_selinux) {
    ++          if (!streq(user_selinux, "")) {
    +                   if (set_seuser (user_name, user_selinux, user_selinux_range) != 0) {
    +                           fprintf (stderr,
    +                                    _("%s: warning: the user name %s to %s SELinux user mapping failed.\n"),
v3b
  • Rebase
$ git range-diff master..gh/streq_empty shadow/master..streq_empty 
1:  7e329852 = 1:  bd4f4f04 lib/, src/: Use streq() instead of its pattern
2:  eb9c40c2 ! 2:  c19d559a lib/, src/: Use !streq() instead of its pattern
    @@ lib/getdate.y: static int LookupWord (char *buff)
          else
     
      ## lib/gshadow.c ##
    -@@ lib/gshadow.c: static /*@null@*/char **build_list (char *s, char **list[], size_t * nlist)
    -   char **ptr = *list;
    -   size_t nelem = *nlist, size;
    +@@ lib/gshadow.c: build_list(char *s)
      
    --  while (s != NULL && *s != '\0') {
    -+  while (s != NULL && !streq(s, "")) {
    -           ptr = XREALLOC(*list, nelem + 1, char *);
    -           ptr[nelem] = strsep(&s, ",");
    -           nelem++;
    +   l = XMALLOC(strchrcnt(s, ',') + 2, char *);
    + 
    +-  for (i = 0; s != NULL && *s != '\0'; i++)
    ++  for (i = 0; s != NULL && !streq(s, ""); i++)
    +           l[i] = strsep(&s, ",");
    + 
    +   l[i] = NULL;
     
      ## lib/limits.c ##
     @@ lib/limits.c: static int do_user_limits (const char *buf, const char *name)
v3c
  • Rebase
$ git range-diff master..gh/streq_empty shadow/master..streq_empty 
1:  bd4f4f04 ! 1:  22adffdb lib/, src/: Use streq() instead of its pattern
    @@ lib/sgetgrent.c: struct group *sgetgrent (const char *buf)
        for (cp = grpbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++)
                grpfields[i] = strsep(&cp, ":");
      
    --  if (i < (NFIELDS - 1) || *grpfields[2] == '\0' || cp != NULL) {
    -+  if (i < (NFIELDS - 1) || streq(grpfields[2], "") || cp != NULL) {
    +-  if (i < NFIELDS || *grpfields[2] == '\0' || cp != NULL) {
    ++  if (i < NFIELDS || streq(grpfields[2], "") || cp != NULL) {
                return NULL;
        }
        grent.gr_name = grpfields[0];
2:  c19d559a = 2:  fdbd9651 lib/, src/: Use !streq() instead of its pattern

@alejandro-colomar alejandro-colomar force-pushed the streq_empty branch 2 times, most recently from 49434cb to a7d1437 Compare December 6, 2024 00:20
@alejandro-colomar alejandro-colomar added the Simpler A good issue for a new beginner label Dec 6, 2024
@alejandro-colomar alejandro-colomar marked this pull request as ready for review December 6, 2024 00:23
@alejandro-colomar alejandro-colomar marked this pull request as draft December 6, 2024 01:22
@alejandro-colomar alejandro-colomar marked this pull request as ready for review December 6, 2024 02:00
@hallyn
Copy link
Member

hallyn commented Dec 6, 2024

lgtm, just needs a rebase.

@alejandro-colomar
Copy link
Collaborator Author

lgtm, just needs a rebase.

Done. Thanks!

(Although it seems I'm late. :)

@alejandro-colomar
Copy link
Collaborator Author

Queued after the release of 4.17.0.

@alejandro-colomar alejandro-colomar marked this pull request as draft December 6, 2024 12:18
@hallyn
Copy link
Member

hallyn commented Dec 6, 2024

Queued after the release of 4.17.0.

But it's draft?

@hallyn
Copy link
Member

hallyn commented Dec 6, 2024

Oh, after release of 4.17.0 - i thought you meant after 4.17.0-rc1.

@alejandro-colomar
Copy link
Collaborator Author

alejandro-colomar commented Dec 6, 2024

Oh, after release of 4.17.0 - i thought you meant after 4.17.0-rc1.

If you want to apply some now (maybe the ones with semantic patch, which can be easily verified), please let me know and I'll un-draft.

But yeah, I prefer to not add much stuff after the RC, so that we get some testing before the release.

@alejandro-colomar
Copy link
Collaborator Author

I'll re-open this one already, because it has a semantic patch for verification. Feel free to merge it or not. I'll leave the others for after the release.

@alejandro-colomar alejandro-colomar marked this pull request as ready for review December 6, 2024 15:40
@hallyn
Copy link
Member

hallyn commented Dec 10, 2024

Oh no I"ve gone and done it again... (needs a rebase)

@alejandro-colomar
Copy link
Collaborator Author

Oh no I"ve gone and done it again... (needs a rebase)

That's fine. Thanks! :-)

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 <[email protected]>
Except for the added (and sorted) includes, the removal of redundant
parentheses, and a few non-string cases that I've left out of the
change, this patch can be approximated with the following semantic
patch:

	$ cat ~/tmp/spatch/strneq.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/strneq.sp;

Signed-off-by: Alejandro Colomar <[email protected]>
@hallyn hallyn merged commit c393055 into shadow-maint:master Dec 10, 2024
9 checks passed
@alejandro-colomar alejandro-colomar deleted the streq_empty branch December 10, 2024 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Simpler A good issue for a new beginner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants