From: Richard Russon Date: Sat, 25 Mar 2017 15:57:40 +0000 (+0000) Subject: tidy: unify sizeof usage X-Git-Tag: neomutt-20170414~19^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4da25073819ff72876ef9b6c8431d3a93d29fbaa;p=neomutt tidy: unify sizeof usage The sizeof operator doesn't always require the argument to be ()'d. However it wasn't used consistently. Add ()s to all uses of sizeof. --- diff --git a/crypt-gpgme.c b/crypt-gpgme.c index 451e5d077..31926a3d5 100644 --- a/crypt-gpgme.c +++ b/crypt-gpgme.c @@ -285,7 +285,7 @@ static crypt_key_t *crypt_copy_key (crypt_key_t *key) { crypt_key_t *k = NULL; - k = safe_calloc (1, sizeof *k); + k = safe_calloc (1, sizeof (*k)); k->kobj = key->kobj; gpgme_key_ref (key->kobj); k->idx = key->idx; @@ -971,7 +971,7 @@ static BODY *sign_message (BODY *a, int use_smime) &t->parameter); /* Get the micalg from gpgme. Old gpgme versions don't support this for S/MIME so we assume sha-1 in this case. */ - if (!get_micalg (ctx, use_smime, buf, sizeof buf)) + if (!get_micalg (ctx, use_smime, buf, sizeof (buf))) mutt_set_parameter ("micalg", buf, &t->parameter); else if (use_smime) mutt_set_parameter ("micalg", "sha1", &t->parameter); @@ -2370,7 +2370,7 @@ int pgp_gpgme_application_handler (BODY *m, STATE *s) but we know that this may only be text thus we assume Latin-1 here. */ if (!mutt_get_body_charset (body_charset, sizeof (body_charset), m)) - strfcpy (body_charset, "iso-8859-1", sizeof body_charset); + strfcpy (body_charset, "iso-8859-1", sizeof (body_charset)); fseeko (s->fpin, m->offset, 0); last_pos = m->offset; @@ -3242,7 +3242,7 @@ parse_dn (const char *string) int i; arraysize = 7; /* C,ST,L,O,OU,CN,email */ - array = safe_malloc ((arraysize+1) * sizeof *array); + array = safe_malloc ((arraysize+1) * sizeof (*array)); arrayidx = 0; while (*string) { @@ -3255,7 +3255,7 @@ parse_dn (const char *string) struct dn_array_s *a2 = NULL; arraysize += 5; - a2 = safe_malloc ((arraysize+1) * sizeof *array); + a2 = safe_malloc ((arraysize+1) * sizeof (*array)); for (i=0; i < arrayidx; i++) { a2[i].key = array[i].key; @@ -3412,9 +3412,9 @@ static void print_key_info (gpgme_key_t key, FILE *fp) tm = localtime (&tt); #ifdef HAVE_LANGINFO_D_T_FMT - strftime (shortbuf, sizeof shortbuf, nl_langinfo (D_T_FMT), tm); + strftime (shortbuf, sizeof (shortbuf), nl_langinfo (D_T_FMT), tm); #else - strftime (shortbuf, sizeof shortbuf, "%c", tm); + strftime (shortbuf, sizeof (shortbuf), "%c", tm); #endif /* L10N: DOTFILL */ fprintf (fp, _("Valid From : %s\n"), shortbuf); @@ -3426,9 +3426,9 @@ static void print_key_info (gpgme_key_t key, FILE *fp) tm = localtime (&tt); #ifdef HAVE_LANGINFO_D_T_FMT - strftime (shortbuf, sizeof shortbuf, nl_langinfo (D_T_FMT), tm); + strftime (shortbuf, sizeof (shortbuf), nl_langinfo (D_T_FMT), tm); #else - strftime (shortbuf, sizeof shortbuf, "%c", tm); + strftime (shortbuf, sizeof (shortbuf), "%c", tm); #endif /* L10N: DOTFILL */ fprintf (fp, _("Valid To ..: %s\n"), shortbuf); @@ -3566,9 +3566,9 @@ static void print_key_info (gpgme_key_t key, FILE *fp) tm = localtime (&tt); #ifdef HAVE_LANGINFO_D_T_FMT - strftime (shortbuf, sizeof shortbuf, nl_langinfo (D_T_FMT), tm); + strftime (shortbuf, sizeof (shortbuf), nl_langinfo (D_T_FMT), tm); #else - strftime (shortbuf, sizeof shortbuf, "%c", tm); + strftime (shortbuf, sizeof (shortbuf), "%c", tm); #endif /* L10N: DOTFILL */ fprintf (fp, _("Valid From : %s\n"), shortbuf); @@ -3580,9 +3580,9 @@ static void print_key_info (gpgme_key_t key, FILE *fp) tm = localtime (&tt); #ifdef HAVE_LANGINFO_D_T_FMT - strftime (shortbuf, sizeof shortbuf, nl_langinfo (D_T_FMT), tm); + strftime (shortbuf, sizeof (shortbuf), nl_langinfo (D_T_FMT), tm); #else - strftime (shortbuf, sizeof shortbuf, "%c", tm); + strftime (shortbuf, sizeof (shortbuf), "%c", tm); #endif /* L10N: DOTFILL */ fprintf (fp, _("Valid To ..: %s\n"), shortbuf); @@ -3794,7 +3794,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app, int secret) if (!n) goto no_pgphints; - patarr = safe_calloc (n+1, sizeof *patarr); + patarr = safe_calloc (n+1, sizeof (*patarr)); for(l=hints, n=0; l; l = l->next) { if (l->data && *l->data) @@ -3832,7 +3832,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app, int secret) for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next) { - k = safe_calloc (1, sizeof *k); + k = safe_calloc (1, sizeof (*k)); k->kobj = key; gpgme_key_ref (k->kobj); k->idx = idx; @@ -3878,7 +3878,7 @@ static crypt_key_t *get_candidates (LIST * hints, unsigned int app, int secret) for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next) { - k = safe_calloc (1, sizeof *k); + k = safe_calloc (1, sizeof (*k)); k->kobj = key; gpgme_key_ref (k->kobj); k->idx = idx; diff --git a/init.c b/init.c index 1f67656b9..b0dec0d25 100644 --- a/init.c +++ b/init.c @@ -3859,7 +3859,7 @@ void mutt_init (int skip_sys_rc, LIST *commands) Fqdn = safe_malloc (mutt_strlen (domain) + mutt_strlen (Hostname) + 2); sprintf (Fqdn, "%s.%s", NONULL(Hostname), domain); /* __SPRINTF_CHECKED__ */ } - else if (!(getdnsdomainname (buffer, sizeof buffer))) + else if (!(getdnsdomainname (buffer, sizeof (buffer)))) { Fqdn = safe_malloc (mutt_strlen (buffer) + mutt_strlen (Hostname) + 2); sprintf (Fqdn, "%s.%s", NONULL(Hostname), buffer); /* __SPRINTF_CHECKED__ */ @@ -4038,38 +4038,38 @@ void mutt_init (int skip_sys_rc, LIST *commands) { do { - if (mutt_set_xdg_path (kXDGConfigDirs, buffer, sizeof buffer)) + if (mutt_set_xdg_path (kXDGConfigDirs, buffer, sizeof (buffer))) break; - snprintf (buffer, sizeof buffer, "%s/neomuttrc-%s", SYSCONFDIR, PACKAGE_VERSION); + snprintf (buffer, sizeof (buffer), "%s/neomuttrc-%s", SYSCONFDIR, PACKAGE_VERSION); if (access (buffer, F_OK) == 0) break; - snprintf (buffer, sizeof buffer, "%s/neomuttrc", SYSCONFDIR); + snprintf (buffer, sizeof (buffer), "%s/neomuttrc", SYSCONFDIR); if (access (buffer, F_OK) == 0) break; - snprintf (buffer, sizeof buffer, "%s/Muttrc-%s", SYSCONFDIR, MUTT_VERSION); + snprintf (buffer, sizeof (buffer), "%s/Muttrc-%s", SYSCONFDIR, MUTT_VERSION); if (access (buffer, F_OK) == 0) break; - snprintf (buffer, sizeof buffer, "%s/Muttrc", SYSCONFDIR); + snprintf (buffer, sizeof (buffer), "%s/Muttrc", SYSCONFDIR); if (access (buffer, F_OK) == 0) break; - snprintf (buffer, sizeof buffer, "%s/neomuttrc-%s", PKGDATADIR, PACKAGE_VERSION); + snprintf (buffer, sizeof (buffer), "%s/neomuttrc-%s", PKGDATADIR, PACKAGE_VERSION); if (access (buffer, F_OK) == 0) break; - snprintf (buffer, sizeof buffer, "%s/neomuttrc", PKGDATADIR); + snprintf (buffer, sizeof (buffer), "%s/neomuttrc", PKGDATADIR); if (access (buffer, F_OK) == 0) break; - snprintf (buffer, sizeof buffer, "%s/Muttrc-%s", PKGDATADIR, MUTT_VERSION); + snprintf (buffer, sizeof (buffer), "%s/Muttrc-%s", PKGDATADIR, MUTT_VERSION); if (access (buffer, F_OK) == 0) break; - snprintf (buffer, sizeof buffer, "%s/Muttrc", PKGDATADIR); + snprintf (buffer, sizeof (buffer), "%s/Muttrc", PKGDATADIR); } while (0); if (access (buffer, F_OK) == 0) { diff --git a/lib.c b/lib.c index 2123c1046..1757b3af2 100644 --- a/lib.c +++ b/lib.c @@ -428,8 +428,8 @@ int safe_symlink(const char *oldpath, const char *newpath) { char abs_oldpath[_POSIX_PATH_MAX]; - if ((getcwd (abs_oldpath, sizeof abs_oldpath) == NULL) || - (strlen (abs_oldpath) + 1 + strlen (oldpath) + 1 > sizeof abs_oldpath)) + if ((getcwd (abs_oldpath, sizeof (abs_oldpath)) == NULL) || + (strlen (abs_oldpath) + 1 + strlen (oldpath) + 1 > sizeof (abs_oldpath))) return -1; strcat (abs_oldpath, "/"); /* __STRCAT_CHECKED__ */ diff --git a/mbox.c b/mbox.c index 15f9e6176..1c91850ee 100644 --- a/mbox.c +++ b/mbox.c @@ -1101,7 +1101,7 @@ static int mbox_sync_mailbox (CONTEXT *ctx, int *index_hint) * sure we seek to the correct location */ if (ctx->magic == MUTT_MMDF) - offset -= (sizeof MMDF_SEP - 1); + offset -= (sizeof (MMDF_SEP) - 1); /* allocate space for the new offsets */ newOffset = safe_calloc (ctx->msgcount - first, sizeof (struct m_update_t)); diff --git a/md5.c b/md5.c index f1b35faaf..55e1cf7b6 100644 --- a/md5.c +++ b/md5.c @@ -87,7 +87,7 @@ md5_init_ctx (struct md5_ctx *ctx) static inline void set_uint32 (char *cp, md5_uint32 v) { - memcpy (cp, &v, sizeof v); + memcpy (cp, &v, sizeof (v)); } /* Put result from CTX in first 16 bytes following RESBUF. The result @@ -96,10 +96,10 @@ void * md5_read_ctx (const struct md5_ctx *ctx, void *resbuf) { char *r = resbuf; - set_uint32 (r + 0 * sizeof ctx->A, SWAP (ctx->A)); - set_uint32 (r + 1 * sizeof ctx->B, SWAP (ctx->B)); - set_uint32 (r + 2 * sizeof ctx->C, SWAP (ctx->C)); - set_uint32 (r + 3 * sizeof ctx->D, SWAP (ctx->D)); + set_uint32 (r + 0 * sizeof (ctx->A), SWAP (ctx->A)); + set_uint32 (r + 1 * sizeof (ctx->B), SWAP (ctx->B)); + set_uint32 (r + 2 * sizeof (ctx->C), SWAP (ctx->C)); + set_uint32 (r + 3 * sizeof (ctx->D), SWAP (ctx->D)); return resbuf; } diff --git a/parse.c b/parse.c index 0e6584b79..81e3f60c3 100644 --- a/parse.c +++ b/parse.c @@ -838,7 +838,7 @@ time_t mutt_parse_date (const char *s, HEADER *h) { struct tz_t *tz = NULL; - tz = bsearch (ptz, TimeZones, sizeof TimeZones/sizeof (struct tz_t), + tz = bsearch (ptz, TimeZones, sizeof (TimeZones)/sizeof (struct tz_t), sizeof (struct tz_t), (int (*)(const void *, const void *)) ascii_strcasecmp /* This is safe to do: A pointer to a struct equals diff --git a/pgplib.h b/pgplib.h index dc541389f..63d5420ae 100644 --- a/pgplib.h +++ b/pgplib.h @@ -83,7 +83,7 @@ void pgp_free_key(pgp_key_t *kpp); static inline pgp_key_t pgp_new_keyinfo(void) { - return safe_calloc (1, sizeof *((pgp_key_t)0)); + return safe_calloc (1, sizeof (*((pgp_key_t)0))); } #endif /* CRYPT_BACKEND_CLASSIC_PGP */ diff --git a/signal.c b/signal.c index aa45b3f47..96cbdd7f9 100644 --- a/signal.c +++ b/signal.c @@ -240,7 +240,7 @@ void mutt_allow_interrupt (int disposition) { struct sigaction sa; - memset (&sa, 0, sizeof sa); + memset (&sa, 0, sizeof (sa)); sa.sa_handler = sighandler; #ifdef SA_RESTART if (disposition == 0)