From: Alejandro Colomar Date: Tue, 23 Jul 2024 20:42:54 +0000 (+0200) Subject: lib/, src/: Consistently use sizeof() as if it were a function X-Git-Tag: 4.19.0-rc1~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d98ccc195e58b10260ef809254444ccec2efa6c6;p=thirdparty%2Fshadow.git 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 --- diff --git a/lib/commonio.c b/lib/commonio.c index d37ba23c9..85bde16b9 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -181,7 +181,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) { @@ -767,7 +767,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]; @@ -905,7 +905,7 @@ int commonio_close (struct commonio_db *db, bool process_selinux) 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 66cec2453..8e4efb59c 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 5d91d201e..69eba5338 100644 --- a/lib/copydir.c +++ b/lib/copydir.c @@ -757,7 +757,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 37951b3b2..95b4ed5c5 100644 --- a/lib/env.c +++ b/lib/env.c @@ -164,7 +164,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 369b215ab..24b8c5dfe 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 72b9c7a7e..2a6f54e5f 100644 --- a/lib/fields.c +++ b/lib/fields.c @@ -62,8 +62,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/getdef.c b/lib/getdef.c index 765cddfa1..930b350bd 100644 --- a/lib/getdef.c +++ b/lib/getdef.c @@ -553,7 +553,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 530996f40..aadc28722 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 d812b4129..92d5336df 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_a(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 51cbc3de3..36ae70616 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_a(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 1b9a417b1..1485f69e2 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/subordinateio.c b/lib/subordinateio.c index ff9e75b88..487d7d48f 100644 --- a/lib/subordinateio.c +++ b/lib/subordinateio.c @@ -93,7 +93,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 2f2c7e2cb..b3c60be9d 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 2ebdced51..78f6593cf 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 8dcbd9389..c265d49d4 100644 --- a/lib/user_busy.c +++ b/lib/user_busy.c @@ -127,7 +127,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 297ca5c7f..41746c033 100644 --- a/lib/utmp.c +++ b/lib/utmp.c @@ -112,7 +112,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; } @@ -306,8 +306,8 @@ prepare_utmp(const char *name, const char *line, const char *host, strncpy_a(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) { @@ -320,21 +320,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 9855303f5..71aa16401 100644 --- a/src/chage.c +++ b/src/chage.c @@ -172,12 +172,12 @@ static int new_fields (void) (void) puts (""); stprintf_a(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; stprintf_a(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; @@ -186,7 +186,7 @@ static int new_fields (void) else day_to_str_a(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; @@ -198,12 +198,12 @@ static int new_fields (void) } stprintf_a(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; stprintf_a(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; @@ -212,7 +212,7 @@ static int new_fields (void) else day_to_str_a(buf, expdate); - change_field (buf, sizeof buf, + change_field(buf, sizeof(buf), _("Account Expiration Date (YYYY-MM-DD)")); if (streq(buf, "-1")) { @@ -614,7 +614,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 2fe99ac19..6fd2c9f58 100644 --- a/src/chfn.c +++ b/src/chfn.c @@ -180,31 +180,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 0e6f5719f..256172f49 100644 --- a/src/chgpasswd.c +++ b/src/chgpasswd.c @@ -476,7 +476,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 %jd: line too long\n"), diff --git a/src/chpasswd.c b/src/chpasswd.c index b67fc9f6b..16a007371 100644 --- a/src/chpasswd.c +++ b/src/chpasswd.c @@ -522,14 +522,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 ce5f5b46e..5a1729c4c 100644 --- a/src/chsh.c +++ b/src/chsh.c @@ -123,7 +123,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 6bb93ae12..2224a50d6 100644 --- a/src/faillog.c +++ b/src/faillog.c @@ -245,7 +245,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; } @@ -266,7 +266,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--; } @@ -341,7 +341,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; } @@ -372,7 +372,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--; } @@ -439,7 +439,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; } @@ -470,7 +470,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 59819616e..228534ea5 100644 --- a/src/groupadd.c +++ b/src/groupadd.c @@ -148,7 +148,7 @@ static void fail_exit(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; @@ -168,7 +168,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_namp = group_name; if (pflg) { sgent->sg_passwd = group_passwd; diff --git a/src/groupmod.c b/src/groupmod.c index a508c197f..9004073fc 100644 --- a/src/groupmod.c +++ b/src/groupmod.c @@ -243,7 +243,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_namp = 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 201fe0621..7cd200ef6 100644 --- a/src/grpconv.c +++ b/src/grpconv.c @@ -215,7 +215,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_namp = gr->gr_name; sgent.sg_passwd = gr->gr_passwd; sgent.sg_adm = ∅ diff --git a/src/lastlog.c b/src/lastlog.c index 46ccc165e..747900fdb 100644 --- a/src/lastlog.c +++ b/src/lastlog.c @@ -119,7 +119,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); @@ -131,7 +131,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 */ @@ -217,12 +217,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; @@ -244,7 +244,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 03d1c92b4..a3ba39e17 100644 --- a/src/login.c +++ b/src/login.c @@ -643,7 +643,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) { stprintf_a(loginprompt, _("%s login: "), hostn); } else { strtcpy_a(loginprompt, _("login: ")); @@ -1203,7 +1203,7 @@ int main (int argc, char **argv) #ifdef HAVE_LL_HOST /* __linux__ || SUN4 */ if (!strneq_a(ll.ll_host, "")) { 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 d51977281..9cd147417 100644 --- a/src/login_nopam.c +++ b/src/login_nopam.c @@ -100,7 +100,7 @@ login_access(const char *user, const char *from) if (NULL != fp) { intmax_t lineno = 0; /* for diagnostics */ while ( !match - && (fgets (line, sizeof (line), fp) == line)) + && (fgets(line, sizeof(line), fp) == line)) { char *p; @@ -183,7 +183,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 fe2b2a908..894e68075 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 %jd: line too long\n"), diff --git a/src/pwconv.c b/src/pwconv.c index a92b1f961..38d0a0a19 100644 --- a/src/pwconv.c +++ b/src/pwconv.c @@ -249,7 +249,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 d3812bec6..4b86afb3f 100644 --- a/src/suauth.c +++ b/src/suauth.c @@ -73,7 +73,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 efc366c9d..fcf9b0d21 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -355,7 +355,7 @@ get_defaults(struct option_flags *flags) * 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, "="); @@ -587,7 +587,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) { @@ -930,7 +930,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; @@ -953,7 +953,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; @@ -1855,7 +1855,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) { @@ -1879,7 +1879,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_namp = (char *) user_name; sgent->sg_passwd = "!"; /* XXX warning: const */ sgent->sg_adm = &empty_list; @@ -1956,14 +1956,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) { @@ -1974,7 +1974,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"), @@ -1994,7 +1994,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; @@ -2008,7 +2008,7 @@ static void lastlog_reset (uid_t uid) return; } - memzero (&ll, sizeof (ll)); + memzero(&ll, sizeof(ll)); fd = open(_PATH_LASTLOG, O_RDWR); if (-1 == fd) { @@ -2019,7 +2019,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 938941c62..a77344e8f 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -1720,7 +1720,7 @@ static void usr_update (struct option_flags *flags) * 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. @@ -1897,8 +1897,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(_PATH_LASTLOG, F_OK) != 0) { @@ -1921,10 +1921,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"), @@ -1936,11 +1936,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"), @@ -1968,8 +1968,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; @@ -1985,10 +1985,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"), @@ -2000,11 +2000,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"),