From f8d0c00886bbd805e2400d01a853136c15906706 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 23 Jul 2024 22:42:54 +0200 Subject: [PATCH] contrib/, lib/, src/: Consistently use sizeof() as if it were a function sizeof(foo) - No spaces. Not: sizeof (foo) - Parentheses. Not: sizeof foo - No parentheses wrapping sizeof itself Not: (sizeof foo) This patch can be approximated with the following semantic patch: $ cat ~/tmp/spatch/sizeof.sp @@ identifier a, b; @@ - sizeof a->b + sizeof(a->b) @@ identifier a, b; @@ - sizeof a.b + sizeof(a.b) @@ identifier x; @@ - sizeof x + sizeof(x) @@ identifier x; @@ - sizeof *x + sizeof(*x) @@ identifier x; @@ - (sizeof(x)) + sizeof(x) @@ identifier x; @@ - (sizeof(*x)) + sizeof(*x) Applied as $ find contrib/ lib* src/ -type f \ | xargs spatch --sp-file ~/tmp/spatch/sizeof.sp --in-place; The differences between the actual patch and the approximation via the semantic patch from above are whitespace only. When reviewing, it'll be useful to diff with '-w'. Link: Signed-off-by: Alejandro Colomar --- contrib/adduser.c | 32 ++++++++++++++++---------------- lib/addgrps.c | 2 +- lib/commonio.c | 6 +++--- lib/console.c | 2 +- lib/copydir.c | 2 +- lib/env.c | 2 +- lib/failure.c | 14 +++++++------- lib/fields.c | 4 ++-- lib/getdate.y | 2 +- lib/getdef.c | 4 ++-- lib/hushed.c | 2 +- lib/log.c | 8 ++++---- lib/loginprompt.c | 4 ++-- lib/setupenv.c | 2 +- lib/sgetpwent.c | 2 +- lib/sgetspent.c | 2 +- lib/shadow.c | 2 +- lib/subordinateio.c | 2 +- lib/ttytype.c | 2 +- lib/tz.c | 2 +- lib/user_busy.c | 4 ++-- lib/utmp.c | 20 ++++++++++---------- src/chage.c | 14 +++++++------- src/chfn.c | 10 +++++----- src/chgpasswd.c | 2 +- src/chpasswd.c | 4 ++-- src/chsh.c | 2 +- src/faillog.c | 12 ++++++------ src/groupadd.c | 4 ++-- src/groupmod.c | 2 +- src/grpconv.c | 2 +- src/lastlog.c | 14 +++++++------- src/login.c | 4 ++-- src/login_nopam.c | 4 ++-- src/newusers.c | 2 +- src/pwconv.c | 2 +- src/suauth.c | 2 +- src/useradd.c | 24 ++++++++++++------------ src/usermod.c | 30 +++++++++++++++--------------- 39 files changed, 128 insertions(+), 128 deletions(-) diff --git a/contrib/adduser.c b/contrib/adduser.c index a8ba99045c..55dc49f252 100644 --- a/contrib/adduser.c +++ b/contrib/adduser.c @@ -204,7 +204,7 @@ main (void) printf ("\nLogin to add (^C to quit): "); fflush (stdout); - safeget (usrname, sizeof (usrname)); + safeget(usrname, sizeof(usrname)); if (!strlen (usrname)) { @@ -239,10 +239,10 @@ main (void) printf ("\nFull Name [%s]: ", usrname); fflush (stdout); - safeget (person, sizeof (person)); + safeget(person, sizeof(person)); if (!strlen (person)) { - bzero (person, sizeof (person)); + bzero(person, sizeof(person)); strcpy (person, usrname); }; @@ -253,7 +253,7 @@ main (void) bad = 0; printf ("GID [%d]: ", DEFAULT_GROUP); fflush (stdout); - safeget (foo, sizeof (foo)); + safeget(foo, sizeof(foo)); if (!strlen (foo)) group = DEFAULT_GROUP; else if (isdigit (*foo)) @@ -294,7 +294,7 @@ main (void) printf ("\nIf home dir ends with a / then '%s' will be appended to it\n", usrname); printf ("Home Directory [%s/%s]: ", DEFAULT_HOME, usrname); fflush (stdout); - safeget (dir, sizeof (dir)); + safeget(dir, sizeof(dir)); if (!strlen(dir)) /* hit return */ sprintf(dir, "%s/%s", DEFAULT_HOME, usrname); else if (dir[strlen (dir) - 1] == '/') @@ -308,7 +308,7 @@ main (void) printf ("\nShell [%s]: ", DEFAULT_SHELL); fflush (stdout); - safeget (shell, sizeof (shell)); + safeget(shell, sizeof(shell)); if (!strlen (shell)) strcpy(shell, DEFAULT_SHELL); else @@ -340,7 +340,7 @@ main (void) #endif printf ("\nMin. Password Change Days [%d]: ", DEFAULT_MIN_PASS); fflush (stdout); - safeget (foo, sizeof (foo)); + safeget(foo, sizeof(foo)); if (strlen (foo) > 1) min_pass = DEFAULT_MIN_PASS; else @@ -348,7 +348,7 @@ main (void) printf ("Max. Password Change Days [%d]: ", DEFAULT_MAX_PASS); fflush (stdout); - safeget (foo, sizeof (foo)); + safeget(foo, sizeof(foo)); if (strlen (foo) > 1) max_pass = atoi (foo); else @@ -356,7 +356,7 @@ main (void) printf ("Password Warning Days [%d]: ", DEFAULT_WARN_PASS); fflush (stdout); - safeget (foo, sizeof (foo)); + safeget(foo, sizeof(foo)); warn_pass = atoi (foo); if (warn_pass == 0) @@ -364,7 +364,7 @@ main (void) printf ("Days after Password Expiry for Account Locking [%d]: ", DEFAULT_USER_DIE); fflush (stdout); - safeget (foo, sizeof (foo)); + safeget(foo, sizeof(foo)); user_die = atoi (foo); if (user_die == 0) user_die = DEFAULT_USER_DIE; @@ -388,7 +388,7 @@ main (void) min_pass, max_pass, warn_pass, user_die); printf ("\nIs this correct? [y/N]: "); fflush (stdout); - safeget (foo, sizeof (foo)); + safeget(foo, sizeof(foo)); done = bad = correct = (strprefix(foo, "y") || strprefix(foo, "Y")); @@ -401,7 +401,7 @@ main (void) *environ = NULL; - bzero (cmd, sizeof (cmd)); + bzero(cmd, sizeof(cmd)); sprintf (cmd, "%s -g %d -d %s -s %s -c \"%s\" -m -k /etc/skel %s", USERADD_PATH, group, dir, shell, person, usrname); printf ("Calling useradd to add new user:\n%s\n", cmd); @@ -419,7 +419,7 @@ main (void) */ setuid (0); - bzero (cmd, sizeof (cmd)); + bzero(cmd, sizeof(cmd)); /* Chage runs suid root. => we need ruid root to run it with * anything other than chage -l @@ -439,7 +439,7 @@ main (void) /* I want to add a user completely with one easy command --chris */ #ifdef HAVE_QUOTAS - bzero (cmd, sizeof (cmd)); + bzero(cmd, sizeof(cmd)); sprintf (cmd, "%s -p %s -u %s", EDQUOTA_PATH, QUOTA_DEFAULT, usrname); printf ("%s\n", cmd); if (system (cmd)) @@ -453,7 +453,7 @@ main (void) printf ("\nDefault quota set.\n"); #endif /* HAVE_QUOTAS */ - bzero (cmd, sizeof (cmd)); + bzero(cmd, sizeof(cmd)); sprintf (cmd, "%s %s", PASSWD_PATH, usrname); if (system (cmd)) { @@ -463,7 +463,7 @@ main (void) #endif } #ifdef IMMEDIATE_CHANGE - bzero (cmd, sizeof (cmd)); + bzero(cmd, sizeof(cmd)); sprintf (cmd, "%s -e %s", PASSWD_PATH, usrname); if (system (cmd)) { diff --git a/lib/addgrps.c b/lib/addgrps.c index 97c47e077f..cbddb043ea 100644 --- a/lib/addgrps.c +++ b/lib/addgrps.c @@ -42,7 +42,7 @@ add_groups(const char *list) int ret; FILE *shadow_logfd = log_get_logfd(); - if (strlen (list) >= sizeof (buf)) { + if (strlen(list) >= sizeof(buf)) { errno = EINVAL; return -1; } diff --git a/lib/commonio.c b/lib/commonio.c index b4784c2088..8a7ccc5e19 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -188,7 +188,7 @@ static int do_lock_file (const char *file, const char *lock, bool log) errno = EINVAL; return 0; } - len = read (fd, buf, sizeof (buf) - 1); + len = read(fd, buf, sizeof(buf) - 1); close (fd); if (len <= 0) { if (log) { @@ -776,7 +776,7 @@ commonio_sort (struct commonio_db *db, int (*cmp) (const void *, const void *)) entries[n] = ptr; n++; } - qsort (entries, n, sizeof (struct commonio_entry *), cmp); + qsort(entries, n, sizeof(struct commonio_entry *), cmp); /* Take care of the head and tail separately */ db->head = entries[0]; @@ -914,7 +914,7 @@ int commonio_close (struct commonio_db *db) goto fail; } - memzero (&sb, sizeof sb); + memzero(&sb, sizeof(sb)); if (NULL != db->fp) { if (fstat (fileno (db->fp), &sb) != 0) { (void) fclose (db->fp); diff --git a/lib/console.c b/lib/console.c index 23d775de8e..35b0c17f92 100644 --- a/lib/console.c +++ b/lib/console.c @@ -76,7 +76,7 @@ is_listed(const char *cfgin, const char *tty, bool def) * See if this tty is listed in the console file. */ - while (fgets (buf, sizeof (buf), fp) != NULL) { + while (fgets(buf, sizeof(buf), fp) != NULL) { stpsep(buf, "\n"); if (streq(buf, tty)) { (void) fclose (fp); diff --git a/lib/copydir.c b/lib/copydir.c index 3a6c132b58..3fc82e4c20 100644 --- a/lib/copydir.c +++ b/lib/copydir.c @@ -760,7 +760,7 @@ static int copy_file (const struct path_info *src, const struct path_info *dst, char buf[8192]; ssize_t cnt; - cnt = read (ifd, buf, sizeof buf); + cnt = read(ifd, buf, sizeof(buf)); if (cnt < 0) { if (errno == EINTR) { continue; diff --git a/lib/env.c b/lib/env.c index 299254225d..aa00d3a953 100644 --- a/lib/env.c +++ b/lib/env.c @@ -163,7 +163,7 @@ void set_env (int argc, char *const *argv) char *cp; for (; argc > 0; argc--, argv++) { - if (strlen (*argv) >= sizeof variable) { + if (strlen(*argv) >= sizeof(variable)) { continue; /* ignore long entries */ } diff --git a/lib/failure.c b/lib/failure.c index afff11aa6a..c079d068e5 100644 --- a/lib/failure.c +++ b/lib/failure.c @@ -34,7 +34,7 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) { int fd; - off_t offset_uid = (off_t) (sizeof *fl) * uid; + off_t offset_uid = (off_t) sizeof(*fl) * uid; /* * Don't do anything if failure logging isn't set up. @@ -59,7 +59,7 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) */ if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid) - || (read (fd, fl, sizeof *fl) != (ssize_t) sizeof *fl)) { + || (read(fd, fl, sizeof(*fl)) != (ssize_t) sizeof(*fl))) { /* This is not necessarily a failure. The file is * initially zero length. * @@ -67,7 +67,7 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) * might reset the counter. But the new failure will be * logged. */ - memzero (fl, sizeof *fl); + memzero(fl, sizeof(*fl)); } /* @@ -92,7 +92,7 @@ void failure (uid_t uid, const char *tty, struct faillog *fl) */ if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid) - || (write_full(fd, fl, sizeof *fl) == -1)) { + || (write_full(fd, fl, sizeof(*fl)) == -1)) { goto err_write; } @@ -150,7 +150,7 @@ int failcheck (uid_t uid, struct faillog *fl, bool failed) { int fd; struct faillog fail; - off_t offset_uid = (off_t) (sizeof *fl) * uid; + off_t offset_uid = (off_t) sizeof(*fl) * uid; /* * Suppress the check if the log file isn't there. @@ -182,7 +182,7 @@ int failcheck (uid_t uid, struct faillog *fl, bool failed) */ if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid) - || (read (fd, fl, sizeof *fl) != (ssize_t) sizeof *fl)) { + || (read(fd, fl, sizeof(*fl)) != (ssize_t) sizeof(*fl))) { (void) close (fd); return 1; } @@ -204,7 +204,7 @@ int failcheck (uid_t uid, struct faillog *fl, bool failed) fail.fail_cnt = 0; if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid) - || (write_full(fd, &fail, sizeof fail) == -1)) { + || (write_full(fd, &fail, sizeof(fail)) == -1)) { goto err_write; } diff --git a/lib/fields.c b/lib/fields.c index ada6726e7f..f24fcee951 100644 --- a/lib/fields.c +++ b/lib/fields.c @@ -74,8 +74,8 @@ change_field(char *buf, size_t maxsize, const char *prompt) char newf[200]; char *cp; - if (maxsize > sizeof (newf)) { - maxsize = sizeof (newf); + if (maxsize > sizeof(newf)) { + maxsize = sizeof(newf); } printf ("\t%s [%s]: ", prompt, buf); diff --git a/lib/getdate.y b/lib/getdate.y index 6fcd8e2ebd..c79ade7c7f 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -772,7 +772,7 @@ yylex (void) if (isalpha (c)) { for (p = buff; (c = *yyInput++, isalpha (c)) || c == '.';) - if (p < &buff[sizeof buff - 1]) + if (p < &buff[sizeof(buff) - 1]) *p++ = c; stpcpy(p, ""); yyInput--; diff --git a/lib/getdef.c b/lib/getdef.c index da3627b084..b6bcccb64c 100644 --- a/lib/getdef.c +++ b/lib/getdef.c @@ -81,7 +81,7 @@ struct itemdef { {"MOTD_FIRSTONLY", NULL}, \ -#define NUMDEFS (sizeof(def_table)/sizeof(def_table[0])) +#define NUMDEFS (sizeof(def_table) / sizeof(def_table[0])) static struct itemdef def_table[] = { {"CHFN_RESTRICT", NULL}, {"CONSOLE_GROUPS", NULL}, @@ -557,7 +557,7 @@ static void def_load (void) /* * Go through all of the lines in the file. */ - while (fgets (buf, sizeof (buf), fp) != NULL) { + while (fgets(buf, sizeof(buf), fp) != NULL) { /* * Trim trailing whitespace. diff --git a/lib/hushed.c b/lib/hushed.c index 526e0f2980..8d5d9c40e1 100644 --- a/lib/hushed.c +++ b/lib/hushed.c @@ -73,7 +73,7 @@ bool hushed (const char *username) if (NULL == fp) { return false; } - for (found = false; !found && (fgets (buf, sizeof buf, fp) == buf);) { + for (found = false; !found && (fgets(buf, sizeof(buf), fp) == buf);) { stpsep(buf, "\n"); found = streq(buf, pw->pw_shell) || streq(buf, pw->pw_name); diff --git a/lib/log.c b/lib/log.c index 87eab365e7..e1b9370805 100644 --- a/lib/log.c +++ b/lib/log.c @@ -55,7 +55,7 @@ void dolastlog ( * for this UID. Negative UID's will create problems, but ... */ - offset = (off_t) pw->pw_uid * sizeof newlog; + offset = (off_t) pw->pw_uid * sizeof(newlog); if (lseek (fd, offset, SEEK_SET) != offset) { SYSLOG ((LOG_WARN, @@ -71,8 +71,8 @@ void dolastlog ( * the way we read the old one in. */ - if (read (fd, &newlog, sizeof newlog) != (ssize_t) sizeof newlog) { - memzero (&newlog, sizeof newlog); + if (read(fd, &newlog, sizeof(newlog)) != (ssize_t) sizeof(newlog)) { + memzero(&newlog, sizeof(newlog)); } if (NULL != ll) { *ll = newlog; @@ -86,7 +86,7 @@ void dolastlog ( STRNCPY(newlog.ll_host, host); #endif if ( (lseek (fd, offset, SEEK_SET) != offset) - || (write_full(fd, &newlog, sizeof newlog) == -1)) { + || (write_full(fd, &newlog, sizeof(newlog)) == -1)) { goto err_write; } diff --git a/lib/loginprompt.c b/lib/loginprompt.c index 7d3e23dc1b..e776cab702 100644 --- a/lib/loginprompt.c +++ b/lib/loginprompt.c @@ -73,7 +73,7 @@ login_prompt(char *name, int namesize) (void) fclose (fp); } } - (void) gethostname (buf, sizeof buf); + (void) gethostname(buf, sizeof(buf)); printf (_("\n%s login: "), buf); (void) fflush (stdout); @@ -83,7 +83,7 @@ login_prompt(char *name, int namesize) */ MEMZERO(buf); - if (fgets (buf, sizeof buf, stdin) != buf) { + if (fgets(buf, sizeof(buf), stdin) != buf) { exit (EXIT_FAILURE); } diff --git a/lib/setupenv.c b/lib/setupenv.c index f010d2a83e..70336c3a0c 100644 --- a/lib/setupenv.c +++ b/lib/setupenv.c @@ -55,7 +55,7 @@ static void read_env_file (const char *filename) if (NULL == fp) { return; } - while (fgets (buf, (int)(sizeof buf), fp) == buf) { + while (fgets(buf, (int) sizeof(buf), fp) == buf) { if (stpsep(buf, "\n") == NULL) break; diff --git a/lib/sgetpwent.c b/lib/sgetpwent.c index b13d5bc546..7fd6e46468 100644 --- a/lib/sgetpwent.c +++ b/lib/sgetpwent.c @@ -51,7 +51,7 @@ sgetpwent(const char *buf) * the password structure remain valid. */ - if (strlen (buf) >= sizeof pwdbuf) { + if (strlen(buf) >= sizeof(pwdbuf)) { fprintf (shadow_logfd, "%s: Too long passwd entry encountered, file corruption?\n", shadow_progname); diff --git a/lib/sgetspent.c b/lib/sgetspent.c index f34853ec69..25cb451f9e 100644 --- a/lib/sgetspent.c +++ b/lib/sgetspent.c @@ -49,7 +49,7 @@ sgetspent(const char *string) * have to do that to our private copy. */ - if (strlen (string) >= sizeof spwbuf) { + if (strlen(string) >= sizeof(spwbuf)) { fprintf (shadow_logfd, "%s: Too long passwd entry encountered, file corruption?\n", shadow_progname); diff --git a/lib/shadow.c b/lib/shadow.c index 3bacd204c3..4e357c2709 100644 --- a/lib/shadow.c +++ b/lib/shadow.c @@ -70,7 +70,7 @@ struct spwd *fgetspent (FILE * fp) return (0); } - if (fgets (buf, sizeof buf, fp) != NULL) + if (fgets(buf, sizeof(buf), fp) != NULL) { stpsep(buf, "\n"); return sgetspent(buf); diff --git a/lib/subordinateio.c b/lib/subordinateio.c index bf02328e79..97993e7e96 100644 --- a/lib/subordinateio.c +++ b/lib/subordinateio.c @@ -92,7 +92,7 @@ subordinate_parse(const char *line) * Copy the string to a temporary buffer so the substrings can * be modified to be NULL terminated. */ - if (strlen (line) >= sizeof rangebuf) + if (strlen(line) >= sizeof(rangebuf)) return NULL; /* fail if too long */ strcpy (rangebuf, line); diff --git a/lib/ttytype.c b/lib/ttytype.c index 3514f2941b..c1aae23e67 100644 --- a/lib/ttytype.c +++ b/lib/ttytype.c @@ -47,7 +47,7 @@ void ttytype (const char *line) perror (typefile); return; } - while (fgets (buf, sizeof buf, fp) == buf) { + while (fgets(buf, sizeof(buf), fp) == buf) { if (strprefix(buf, "#")) { continue; } diff --git a/lib/tz.c b/lib/tz.c index b854a593b5..dd5c069868 100644 --- a/lib/tz.c +++ b/lib/tz.c @@ -37,7 +37,7 @@ fp = fopen (fname, "r"); if ( (NULL == fp) - || (fgets (tzbuf, sizeof (tzbuf), fp) == NULL)) { + || (fgets(tzbuf, sizeof(tzbuf), fp) == NULL)) { result = "TZ=CST6CDT"; } else { stpsep(tzbuf, "\n"); diff --git a/lib/user_busy.c b/lib/user_busy.c index d689d34d60..0b92359d75 100644 --- a/lib/user_busy.c +++ b/lib/user_busy.c @@ -70,7 +70,7 @@ user_busy_utmp(const char *name) if (utent->ut_type != USER_PROCESS) { continue; } - if (strncmp (utent->ut_user, name, sizeof utent->ut_user) != 0) { + if (strncmp(utent->ut_user, name, sizeof(utent->ut_user)) != 0) { continue; } if (kill (utent->ut_pid, 0) != 0) { @@ -126,7 +126,7 @@ static int check_status (const char *name, const char *sname, uid_t uid) if (NULL == sfile) { return 0; } - while (fgets (line, sizeof (line), sfile) == line) { + while (fgets(line, sizeof(line), sfile) == line) { if (strprefix(line, "Uid:\t")) { unsigned long ruid, euid, suid; diff --git a/lib/utmp.c b/lib/utmp.c index d73b463a4f..75acfb8a26 100644 --- a/lib/utmp.c +++ b/lib/utmp.c @@ -110,7 +110,7 @@ failtmp(const char *username, const struct utmpx *failent) * Append the new failure record and close the log file. */ - if (write_full(fd, failent, sizeof *failent) == -1) { + if (write_full(fd, failent, sizeof(*failent)) == -1) { goto err_write; } @@ -171,7 +171,7 @@ get_current_utmp(void) if (NULL != ut) { ret = XMALLOC(1, struct utmpx); - memcpy (ret, ut, sizeof (*ret)); + memcpy(ret, ut, sizeof(*ret)); } endutxent(); @@ -286,8 +286,8 @@ prepare_utmp(const char *name, const char *line, const char *host, STRNCPY(utent->ut_host, hostname); #endif #if defined(HAVE_STRUCT_UTMPX_UT_SYSLEN) - utent->ut_syslen = MIN (strlen (hostname), - sizeof (utent->ut_host)); + utent->ut_syslen = MIN(strlen(hostname), + sizeof(utent->ut_host)); #endif #if defined(HAVE_STRUCT_UTMPX_UT_ADDR) || defined(HAVE_STRUCT_UTMPX_UT_ADDR_V6) if (getaddrinfo (hostname, NULL, NULL, &info) == 0) { @@ -300,21 +300,21 @@ prepare_utmp(const char *name, const char *line, const char *host, # if defined(HAVE_STRUCT_UTMPX_UT_ADDR) memcpy (&(utent->ut_addr), &(sa->sin_addr), - MIN (sizeof (utent->ut_addr), - sizeof (sa->sin_addr))); + MIN(sizeof(utent->ut_addr), + sizeof(sa->sin_addr))); # endif # if defined(HAVE_STRUCT_UTMPX_UT_ADDR_V6) memcpy (utent->ut_addr_v6, &(sa->sin_addr), - MIN (sizeof (utent->ut_addr_v6), - sizeof (sa->sin_addr))); + MIN(sizeof(utent->ut_addr_v6), + sizeof(sa->sin_addr))); } else if (info->ai_family == AF_INET6) { struct sockaddr_in6 *sa = (struct sockaddr_in6 *) info->ai_addr; memcpy (utent->ut_addr_v6, &(sa->sin6_addr), - MIN (sizeof (utent->ut_addr_v6), - sizeof (sa->sin6_addr))); + MIN(sizeof(utent->ut_addr_v6), + sizeof(sa->sin6_addr))); # endif } freeaddrinfo (info); diff --git a/src/chage.c b/src/chage.c index a7933e0d88..01eaede1af 100644 --- a/src/chage.c +++ b/src/chage.c @@ -171,12 +171,12 @@ static int new_fields (void) (void) puts (""); SNPRINTF(buf, "%ld", mindays); - change_field (buf, sizeof buf, _("Minimum Password Age")); + change_field(buf, sizeof(buf), _("Minimum Password Age")); if (a2sl(&mindays, buf, NULL, 0, -1, LONG_MAX) == -1) return 0; SNPRINTF(buf, "%ld", maxdays); - change_field (buf, sizeof buf, _("Maximum Password Age")); + change_field(buf, sizeof(buf), _("Maximum Password Age")); if (a2sl(&maxdays, buf, NULL, 0, -1, LONG_MAX) == -1) return 0; @@ -185,7 +185,7 @@ static int new_fields (void) else DAY_TO_STR(buf, lstchgdate); - change_field (buf, sizeof buf, _("Last Password Change (YYYY-MM-DD)")); + change_field(buf, sizeof(buf), _("Last Password Change (YYYY-MM-DD)")); if (streq(buf, "-1")) { lstchgdate = -1; @@ -197,12 +197,12 @@ static int new_fields (void) } SNPRINTF(buf, "%ld", warndays); - change_field (buf, sizeof buf, _("Password Expiration Warning")); + change_field(buf, sizeof(buf), _("Password Expiration Warning")); if (a2sl(&warndays, buf, NULL, 0, -1, LONG_MAX) == -1) return 0; SNPRINTF(buf, "%ld", inactdays); - change_field (buf, sizeof buf, _("Password Inactive")); + change_field(buf, sizeof(buf), _("Password Inactive")); if (a2sl(&inactdays, buf, NULL, 0, -1, LONG_MAX) == -1) return 0; @@ -211,7 +211,7 @@ static int new_fields (void) else DAY_TO_STR(buf, expdate); - change_field (buf, sizeof buf, + change_field(buf, sizeof(buf), _("Account Expiration Date (YYYY-MM-DD)")); if (streq(buf, "-1")) { @@ -644,7 +644,7 @@ static void update_age (/*@null@*/const struct spwd *sp, if (NULL == sp) { struct passwd pwent = *pw; - memzero (&spwent, sizeof spwent); + memzero(&spwent, sizeof(spwent)); spwent.sp_namp = xstrdup (pwent.pw_name); spwent.sp_pwdp = xstrdup (pwent.pw_passwd); spwent.sp_flag = SHADOW_SP_FLAG_UNSET; diff --git a/src/chfn.c b/src/chfn.c index 1b234f4706..8cfb959632 100644 --- a/src/chfn.c +++ b/src/chfn.c @@ -176,31 +176,31 @@ static void new_fields (void) puts (_("Enter the new value, or press ENTER for the default")); if (may_change_field ('f')) { - change_field (fullnm, sizeof fullnm, _("Full Name")); + change_field(fullnm, sizeof(fullnm), _("Full Name")); } else { printf (_("\t%s: %s\n"), _("Full Name"), fullnm); } if (may_change_field ('r')) { - change_field (roomno, sizeof roomno, _("Room Number")); + change_field(roomno, sizeof(roomno), _("Room Number")); } else { printf (_("\t%s: %s\n"), _("Room Number"), roomno); } if (may_change_field ('w')) { - change_field (workph, sizeof workph, _("Work Phone")); + change_field(workph, sizeof(workph), _("Work Phone")); } else { printf (_("\t%s: %s\n"), _("Work Phone"), workph); } if (may_change_field ('h')) { - change_field (homeph, sizeof homeph, _("Home Phone")); + change_field(homeph, sizeof(homeph), _("Home Phone")); } else { printf (_("\t%s: %s\n"), _("Home Phone"), homeph); } if (amroot) { - change_field (slop, sizeof slop, _("Other")); + change_field(slop, sizeof(slop), _("Other")); } } diff --git a/src/chgpasswd.c b/src/chgpasswd.c index 2d50337e64..a85e47a378 100644 --- a/src/chgpasswd.c +++ b/src/chgpasswd.c @@ -460,7 +460,7 @@ int main (int argc, char **argv) * group entry for each group will be looked up in the appropriate * file (gshadow or group) and the password changed. */ - while (fgets (buf, (int) sizeof buf, stdin) != NULL) { + while (fgets(buf, (int) sizeof(buf), stdin) != NULL) { line++; if (stpsep(buf, "\n") == NULL) { fprintf (stderr, _("%s: line %d: line too long\n"), diff --git a/src/chpasswd.c b/src/chpasswd.c index 51adba019a..32a0bb2183 100644 --- a/src/chpasswd.c +++ b/src/chpasswd.c @@ -501,14 +501,14 @@ int main (int argc, char **argv) * last change date is set in the age only if aging information is * present. */ - while (fgets (buf, sizeof buf, stdin) != NULL) { + while (fgets(buf, sizeof(buf), stdin) != NULL) { char *cp; line++; if (stpsep(buf, "\n") == NULL) { if (feof (stdin) == 0) { // Drop all remaining characters on this line. - while (fgets (buf, sizeof buf, stdin) != NULL) { + while (fgets(buf, sizeof(buf), stdin) != NULL) { if (strchr(buf, '\n')) break; } diff --git a/src/chsh.c b/src/chsh.c index 15bfae3237..5e936d481a 100644 --- a/src/chsh.c +++ b/src/chsh.c @@ -118,7 +118,7 @@ usage (int status) static void new_fields (void) { puts (_("Enter the new value, or press ENTER for the default")); - change_field (loginsh, sizeof loginsh, _("Login Shell")); + change_field(loginsh, sizeof(loginsh), _("Login Shell")); } /* diff --git a/src/faillog.c b/src/faillog.c index 709d741cef..70645717e8 100644 --- a/src/faillog.c +++ b/src/faillog.c @@ -244,7 +244,7 @@ static bool reset_one (uid_t uid) fl.fail_cnt = 0; if ( (fseeko (fail, offset, SEEK_SET) == 0) - && (fwrite (&fl, sizeof (fl), 1, fail) == 1)) { + && (fwrite(&fl, sizeof(fl), 1, fail) == 1)) { (void) fflush (fail); return false; } @@ -265,7 +265,7 @@ static void reset (void) /* There is no need to reset outside of the faillog * database. */ - uid_t uidmax = statbuf.st_size / sizeof (struct faillog); + uid_t uidmax = statbuf.st_size / sizeof(struct faillog); if (uidmax > 1) { uidmax--; } @@ -340,7 +340,7 @@ static bool setmax_one (uid_t uid, short max) fl.fail_max = max; if ( (fseeko (fail, offset, SEEK_SET) == 0) - && (fwrite (&fl, sizeof (fl), 1, fail) == 1)) { + && (fwrite(&fl, sizeof(fl), 1, fail) == 1)) { (void) fflush (fail); return false; } @@ -371,7 +371,7 @@ static void setmax (short max) /* The default umax value is based on the size of the * faillog database. */ - uid_t uidmax = statbuf.st_size / sizeof (struct faillog); + uid_t uidmax = statbuf.st_size / sizeof(struct faillog); if (uidmax > 1) { uidmax--; } @@ -438,7 +438,7 @@ static bool set_locktime_one (uid_t uid, long locktime) fl.fail_locktime = locktime; if ( (fseeko (fail, offset, SEEK_SET) == 0) - && (fwrite (&fl, sizeof (fl), 1, fail) == 1)) { + && (fwrite(&fl, sizeof(fl), 1, fail) == 1)) { (void) fflush (fail); return false; } @@ -469,7 +469,7 @@ static void set_locktime (long locktime) /* The default umax value is based on the size of the * faillog database. */ - uid_t uidmax = statbuf.st_size / sizeof (struct faillog); + uid_t uidmax = statbuf.st_size / sizeof(struct faillog); if (uidmax > 1) { uidmax--; } diff --git a/src/groupadd.c b/src/groupadd.c index 9f0eb2e50f..846f313330 100644 --- a/src/groupadd.c +++ b/src/groupadd.c @@ -128,7 +128,7 @@ usage (int status) */ static void new_grent (struct group *grent) { - memzero (grent, sizeof *grent); + memzero(grent, sizeof(*grent)); grent->gr_name = group_name; if (pflg) { grent->gr_passwd = group_passwd; @@ -148,7 +148,7 @@ static void new_grent (struct group *grent) */ static void new_sgent (struct sgrp *sgent) { - memzero (sgent, sizeof *sgent); + memzero(sgent, sizeof(*sgent)); sgent->sg_name = group_name; if (pflg) { sgent->sg_passwd = group_passwd; diff --git a/src/groupmod.c b/src/groupmod.c index 7342707d06..b9ab8aa86c 100644 --- a/src/groupmod.c +++ b/src/groupmod.c @@ -237,7 +237,7 @@ grp_update(void) * shadowed password, we force the creation of a * gshadow entry when a new password is requested. */ - bzero(&sgrp, sizeof sgrp); + bzero(&sgrp, sizeof(sgrp)); sgrp.sg_name = xstrdup (grp.gr_name); sgrp.sg_passwd = xstrdup (grp.gr_passwd); sgrp.sg_adm = ∅ diff --git a/src/grpconv.c b/src/grpconv.c index 16cd52c9a2..c1c89faeca 100644 --- a/src/grpconv.c +++ b/src/grpconv.c @@ -204,7 +204,7 @@ int main (int argc, char **argv) static char *empty = NULL; /* add new shadow group entry */ - bzero(&sgent, sizeof sgent); + bzero(&sgent, sizeof(sgent)); sgent.sg_name = gr->gr_name; sgent.sg_passwd = gr->gr_passwd; sgent.sg_adm = ∅ diff --git a/src/lastlog.c b/src/lastlog.c index d622ba84e7..15ad76719b 100644 --- a/src/lastlog.c +++ b/src/lastlog.c @@ -115,8 +115,8 @@ static void print_one (/*@null@*/const struct passwd *pw) } - offset = (off_t) pw->pw_uid * sizeof (ll); - if (offset + sizeof (ll) <= statbuf.st_size) { + offset = (off_t) pw->pw_uid * sizeof(ll); + if (offset + sizeof(ll) <= statbuf.st_size) { /* fseeko errors are not really relevant for us. */ int err = fseeko (lastlogfile, offset, SEEK_SET); assert (0 == err); @@ -124,7 +124,7 @@ static void print_one (/*@null@*/const struct passwd *pw) * entered for this user, which should be able to get the * empty entry in this case. */ - if (fread (&ll, sizeof (ll), 1, lastlogfile) != 1) { + if (fread(&ll, sizeof(ll), 1, lastlogfile) != 1) { fprintf (stderr, _("%s: Failed to get the entry for UID %lu\n"), Prog, (unsigned long)pw->pw_uid); @@ -136,7 +136,7 @@ static void print_one (/*@null@*/const struct passwd *pw) * as if we were reading an non existing entry in the * sparse lastlog file). */ - memzero (&ll, sizeof (ll)); + memzero(&ll, sizeof(ll)); } /* Filter out entries that do not match with the -t or -b options */ @@ -222,12 +222,12 @@ static void update_one (/*@null@*/const struct passwd *pw) return; } - offset = (off_t) pw->pw_uid * sizeof (ll); + offset = (off_t) pw->pw_uid * sizeof(ll); /* fseeko errors are not really relevant for us. */ err = fseeko (lastlogfile, offset, SEEK_SET); assert (0 == err); - memzero (&ll, sizeof (ll)); + memzero(&ll, sizeof(ll)); if (Sflg) { ll.ll_time = NOW; @@ -249,7 +249,7 @@ static void update_one (/*@null@*/const struct passwd *pw) } #endif - if (fwrite (&ll, sizeof(ll), 1, lastlogfile) != 1) { + if (fwrite(&ll, sizeof(ll), 1, lastlogfile) != 1) { fprintf (stderr, _("%s: Failed to update the entry for UID %lu\n"), Prog, (unsigned long)pw->pw_uid); diff --git a/src/login.c b/src/login.c index 3cfdc29cb0..8a210c0bb3 100644 --- a/src/login.c +++ b/src/login.c @@ -650,7 +650,7 @@ int main (int argc, char **argv) unsigned int failcount = 0; /* Make the login prompt look like we want it */ - if (gethostname (hostn, sizeof (hostn)) == 0) { + if (gethostname(hostn, sizeof(hostn)) == 0) { SNPRINTF(loginprompt, _("%s login: "), hostn); } else { STRTCPY(loginprompt, _("login: ")); @@ -1209,7 +1209,7 @@ int main (int argc, char **argv) #ifdef HAVE_LL_HOST /* __linux__ || SUN4 */ if ('\0' != ll.ll_host[0]) { printf (_(" from %.*s"), - (int) sizeof ll.ll_host, ll.ll_host); + (int) sizeof(ll.ll_host), ll.ll_host); } #endif printf (".\n"); diff --git a/src/login_nopam.c b/src/login_nopam.c index 4f147d3f46..037df40e14 100644 --- a/src/login_nopam.c +++ b/src/login_nopam.c @@ -97,7 +97,7 @@ login_access(const char *user, const char *from) if (NULL != fp) { int lineno = 0; /* for diagnostics */ while ( !match - && (fgets (line, sizeof (line), fp) == line)) + && (fgets(line, sizeof(line), fp) == line)) { char *p; @@ -185,7 +185,7 @@ static char *myhostname (void) static char name[MAXHOSTNAMELEN + 1] = ""; if (streq(name, "")) { - gethostname (name, sizeof (name)); + gethostname(name, sizeof(name)); stpcpy(&name[MAXHOSTNAMELEN], ""); } return (name); diff --git a/src/newusers.c b/src/newusers.c index 5e78dd9760..130c812f49 100644 --- a/src/newusers.c +++ b/src/newusers.c @@ -1109,7 +1109,7 @@ int main (int argc, char **argv) * over 100 is allocated. The pw_gid field will be updated with that * value. */ - while (fgets (buf, sizeof buf, stdin) != NULL) { + while (fgets(buf, sizeof(buf), stdin) != NULL) { line++; if (stpsep(buf, "\n") == NULL && feof(stdin) == 0) { fprintf (stderr, _("%s: line %d: line too long\n"), diff --git a/src/pwconv.c b/src/pwconv.c index 1bb9275288..46f100065a 100644 --- a/src/pwconv.c +++ b/src/pwconv.c @@ -240,7 +240,7 @@ int main (int argc, char **argv) spent = *sp; } else { /* add new shadow entry */ - bzero(&spent, sizeof spent); + bzero(&spent, sizeof(spent)); spent.sp_namp = pw->pw_name; spent.sp_min = getdef_num ("PASS_MIN_DAYS", -1); spent.sp_max = getdef_num ("PASS_MAX_DAYS", -1); diff --git a/src/suauth.c b/src/suauth.c index 25ab3b3f01..596344de42 100644 --- a/src/suauth.c +++ b/src/suauth.c @@ -72,7 +72,7 @@ check_su_auth(const char *actual_id, const char *wanted_id, bool su_to_root) return DENY; } - while (fgets (temp, sizeof (temp), authfile_fd) != NULL) { + while (fgets(temp, sizeof(temp), authfile_fd) != NULL) { char *p; lines++; diff --git a/src/useradd.c b/src/useradd.c index 9ba7c13b7d..f943f24a67 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -362,7 +362,7 @@ get_defaults(void) * Read the file a line at a time. Only the lines that have relevant * values are used, everything else can be ignored. */ - while (fgets (buf, sizeof buf, fp) == buf) { + while (fgets(buf, sizeof(buf), fp) == buf) { stpsep(buf, "\n"); cp = stpsep(buf, "="); @@ -602,7 +602,7 @@ set_defaults(void) goto skip; } - while (fgets (buf, sizeof buf, ifp) == buf) { + while (fgets(buf, sizeof(buf), ifp) == buf) { char *val; if (stpsep(buf, "\n") == NULL) { @@ -948,7 +948,7 @@ static void usage (int status) */ static void new_pwent (struct passwd *pwent) { - memzero (pwent, sizeof *pwent); + memzero(pwent, sizeof(*pwent)); pwent->pw_name = (char *) user_name; if (is_shadow_pwd) { pwent->pw_passwd = (char *) SHADOW_PASSWD_STRING; @@ -971,7 +971,7 @@ static void new_pwent (struct passwd *pwent) */ static void new_spent (struct spwd *spent) { - memzero (spent, sizeof *spent); + memzero(spent, sizeof(*spent)); spent->sp_namp = (char *) user_name; spent->sp_pwdp = (char *) user_pass; spent->sp_lstchg = gettime () / DAY; @@ -1889,7 +1889,7 @@ static char *empty_list = NULL; static void new_grent (struct group *grent) { - memzero (grent, sizeof *grent); + memzero(grent, sizeof(*grent)); grent->gr_name = (char *) user_name; #ifdef SHADOWGRP if (is_shadow_grp) { @@ -1913,7 +1913,7 @@ static void new_grent (struct group *grent) static void new_sgent (struct sgrp *sgent) { - memzero (sgent, sizeof *sgent); + memzero(sgent, sizeof(*sgent)); sgent->sg_name = (char *) user_name; sgent->sg_passwd = "!"; /* XXX warning: const */ sgent->sg_adm = &empty_list; @@ -1990,14 +1990,14 @@ static void faillog_reset (uid_t uid) { struct faillog fl; int fd; - off_t offset_uid = (off_t) (sizeof fl) * uid; + off_t offset_uid = (off_t) sizeof(fl) * uid; struct stat st; if (stat (FAILLOG_FILE, &st) != 0 || st.st_size <= offset_uid) { return; } - memzero (&fl, sizeof (fl)); + memzero(&fl, sizeof(fl)); fd = open (FAILLOG_FILE, O_RDWR); if (-1 == fd) { @@ -2008,7 +2008,7 @@ static void faillog_reset (uid_t uid) return; } if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid) - || (write_full(fd, &fl, sizeof (fl)) == -1) + || (write_full(fd, &fl, sizeof(fl)) == -1) || (fsync (fd) != 0)) { fprintf (stderr, _("%s: failed to reset the faillog entry of UID %lu: %s\n"), @@ -2028,7 +2028,7 @@ static void lastlog_reset (uid_t uid) { struct lastlog ll; int fd; - off_t offset_uid = (off_t) (sizeof ll) * uid; + off_t offset_uid = (off_t) sizeof(ll) * uid; uid_t max_uid; struct stat st; @@ -2042,7 +2042,7 @@ static void lastlog_reset (uid_t uid) return; } - memzero (&ll, sizeof (ll)); + memzero(&ll, sizeof(ll)); fd = open (LASTLOG_FILE, O_RDWR); if (-1 == fd) { @@ -2053,7 +2053,7 @@ static void lastlog_reset (uid_t uid) return; } if ( (lseek (fd, offset_uid, SEEK_SET) != offset_uid) - || (write_full (fd, &ll, sizeof (ll)) == -1) + || (write_full(fd, &ll, sizeof(ll)) == -1) || (fsync (fd) != 0)) { fprintf (stderr, _("%s: failed to reset the lastlog entry of UID %lu: %s\n"), diff --git a/src/usermod.c b/src/usermod.c index 0a09bfa165..769097caa6 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -1736,7 +1736,7 @@ static void usr_update (void) * a shadowed password * + aging information is requested */ - bzero(&spent, sizeof spent); + bzero(&spent, sizeof(spent)); spent.sp_namp = user_name; /* The user explicitly asked for a shadow feature. @@ -1914,8 +1914,8 @@ static void update_lastlog (void) { struct lastlog ll; int fd; - off_t off_uid = (off_t) user_id * sizeof ll; - off_t off_newuid = (off_t) user_newid * sizeof ll; + off_t off_uid = (off_t) user_id * sizeof(ll); + off_t off_newuid = (off_t) user_newid * sizeof(ll); uid_t max_uid; if (access (LASTLOG_FILE, F_OK) != 0) { @@ -1938,10 +1938,10 @@ static void update_lastlog (void) } if ( (lseek (fd, off_uid, SEEK_SET) == off_uid) - && (read (fd, &ll, sizeof ll) == (ssize_t) sizeof ll)) { + && (read(fd, &ll, sizeof(ll)) == (ssize_t) sizeof(ll))) { /* Copy the old entry to its new location */ if ( (lseek (fd, off_newuid, SEEK_SET) != off_newuid) - || (write_full(fd, &ll, sizeof ll) == -1) + || (write_full(fd, &ll, sizeof(ll)) == -1) || (fsync (fd) != 0)) { fprintf (stderr, _("%s: failed to copy the lastlog entry of user %lu to user %lu: %s\n"), @@ -1953,11 +1953,11 @@ static void update_lastlog (void) /* Check if the new UID already has an entry */ if ( (lseek (fd, off_newuid, SEEK_SET) == off_newuid) - && (read (fd, &ll, sizeof ll) == (ssize_t) sizeof ll)) { + && (read(fd, &ll, sizeof(ll)) == (ssize_t) sizeof(ll))) { /* Reset the new uid's lastlog entry */ - memzero (&ll, sizeof (ll)); + memzero(&ll, sizeof(ll)); if ( (lseek (fd, off_newuid, SEEK_SET) != off_newuid) - || (write_full(fd, &ll, sizeof ll) == -1) + || (write_full(fd, &ll, sizeof(ll)) == -1) || (fsync (fd) != 0)) { fprintf (stderr, _("%s: failed to copy the lastlog entry of user %lu to user %lu: %s\n"), @@ -1985,8 +1985,8 @@ static void update_faillog (void) { struct faillog fl; int fd; - off_t off_uid = (off_t) user_id * sizeof fl; - off_t off_newuid = (off_t) user_newid * sizeof fl; + off_t off_uid = (off_t) user_id * sizeof(fl); + off_t off_newuid = (off_t) user_newid * sizeof(fl); if (access (FAILLOG_FILE, F_OK) != 0) { return; @@ -2002,10 +2002,10 @@ static void update_faillog (void) } if ( (lseek (fd, off_uid, SEEK_SET) == off_uid) - && (read (fd, &fl, sizeof fl) == (ssize_t) sizeof fl)) { + && (read(fd, &fl, sizeof(fl)) == (ssize_t) sizeof(fl))) { /* Copy the old entry to its new location */ if ( (lseek (fd, off_newuid, SEEK_SET) != off_newuid) - || (write_full(fd, &fl, sizeof fl) == -1) + || (write_full(fd, &fl, sizeof(fl)) == -1) || (fsync (fd) != 0)) { fprintf (stderr, _("%s: failed to copy the faillog entry of user %lu to user %lu: %s\n"), @@ -2017,11 +2017,11 @@ static void update_faillog (void) /* Check if the new UID already has an entry */ if ( (lseek (fd, off_newuid, SEEK_SET) == off_newuid) - && (read (fd, &fl, sizeof fl) == (ssize_t) sizeof fl)) { + && (read(fd, &fl, sizeof(fl)) == (ssize_t) sizeof(fl))) { /* Reset the new uid's faillog entry */ - memzero (&fl, sizeof (fl)); + memzero(&fl, sizeof(fl)); if ( (lseek (fd, off_newuid, SEEK_SET) != off_newuid) - || (write_full(fd, &fl, sizeof fl) == -1)) + || (write_full(fd, &fl, sizeof(fl)) == -1)) { fprintf (stderr, _("%s: failed to copy the faillog entry of user %lu to user %lu: %s\n"),