]> granicus.if.org Git - mutt/commitdiff
Remove unnecessary "" checks for DT_STR and DT_PATH MuttVars.
authorKevin McCarthy <kevin@8t8.us>
Thu, 27 Jun 2019 22:35:12 +0000 (15:35 -0700)
committerKevin McCarthy <kevin@8t8.us>
Fri, 28 Jun 2019 19:44:02 +0000 (12:44 -0700)
MuttVars of those types are set via safe_strdup(), which returns NULL
if the original is "".  Thus Var implies *Var.

A good portion of the code relies on that axiom, but over the years
some (Var && *Var) checks have crept in, including from me.

This was partially because of the INITVAL("") that were in the code,
which implied (incorrectly) the initial value could be "".  Commit
2f91d43e removed those to make it more clear.

This commit removes the *Var checks to make it even clearer, and help
avoid them creeping back in again.

26 files changed:
alias.c
bcache.c
charset.c
commands.c
compose.c
crypt-gpgme.c
crypt.c
curs_main.c
handler.c
hcache.c
hook.c
imap/auth.c
imap/auth_oauth.c
init.c
mutt_socket.c
muttlib.c
parse.c
pgpinvoke.c
pop_auth.c
rfc1524.c
rfc2047.c
rfc2231.c
send.c
sendlib.c
smime.c
smtp.c

diff --git a/alias.c b/alias.c
index 593d5d999cf304341fa9c5399358cb400e6f0297..c3051bf981e9cf18241c602f401dc8958d5ecae3 100644 (file)
--- a/alias.c
+++ b/alias.c
@@ -215,7 +215,7 @@ static void recode_buf (char *buf, size_t buflen)
 {
   char *s;
 
-  if (!ConfigCharset || !*ConfigCharset || !Charset)
+  if (!ConfigCharset || !Charset)
     return;
   s = safe_strdup (buf);
   if (!s)
index 62838fd40c3e9c7f21082aa7d41f874a272840e7..5530d0cfaf9f4e294a8245122341b066c66297c5 100644 (file)
--- a/bcache.c
+++ b/bcache.c
@@ -46,7 +46,7 @@ static int bcache_path(ACCOUNT *account, const char *mailbox,
   ciss_url_t url;
   int len;
 
-  if (!account || !MessageCachedir || !*MessageCachedir || !dst || !dstlen)
+  if (!account || !MessageCachedir || !dst || !dstlen)
     return -1;
 
   /* make up a ciss_url_t we can turn into a string */
index 759c2052bb0971fe47e951bade2995528476fcf1..7afaeb8bb46dcd1bc9aed3a322faca68ac9ed8c1 100644 (file)
--- a/charset.c
+++ b/charset.c
@@ -317,7 +317,7 @@ char *mutt_get_default_charset ()
   const char *c = AssumedCharset;
   const char *c1;
 
-  if (c && *c)
+  if (c)
   {
     c1 = strchr (c, ':');
     strfcpy (fcharset, c, c1 ? (c1 - c + 1) : sizeof (fcharset));
index 15f6dbbca44975bbc22295afbeb44a18bb07591e..ac8a120bf8fb19f03a27df188fa8177d3db8c1ba 100644 (file)
@@ -194,7 +194,7 @@ int mutt_display_message (HEADER *cur)
     return (0);
   }
 
-  if (DisplayFilter && *DisplayFilter)
+  if (DisplayFilter)
   {
     fpfilterout = fpout;
     fpout = NULL;
@@ -585,7 +585,7 @@ void mutt_pipe_message (HEADER *h)
 void mutt_print_message (HEADER *h)
 {
 
-  if (quadoption (OPT_PRINT) && (!PrintCmd || !*PrintCmd))
+  if (quadoption (OPT_PRINT) && !PrintCmd)
   {
     mutt_message (_("No printing command has been defined."));
     return;
index 05ad4d47771ea7193c5a56fecc784b9b7ef0a831..4d1b713528e2440613c1a18184e3cf25724c7384 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -260,8 +260,7 @@ static void redraw_crypt_lines (HEADER *msg)
   if ((WithCrypto & APPLICATION_SMIME)
       && (msg->security & APPLICATION_SMIME)
       && (msg->security & ENCRYPT)
-      && SmimeCryptAlg
-      && *SmimeCryptAlg)
+      && SmimeCryptAlg)
   {
     SETCOLOR (MT_COLOR_COMPOSE_HEADER);
     mutt_window_mvprintw (MuttIndexWindow, HDR_CRYPTINFO, 40, "%s", _("Encrypt with: "));
index 696daa624179ddf2890b23832e33abfdbe05fb61..bbdede5f806695db5d33af2917e0da2832bde893 100644 (file)
@@ -943,11 +943,11 @@ static int set_signer (gpgme_ctx_t ctx, int for_smime)
   char *fpr, *fpr2;
 
   if (for_smime)
-    signid = (SmimeSignAs && *SmimeSignAs) ? SmimeSignAs : SmimeDefaultKey;
+    signid = SmimeSignAs ? SmimeSignAs : SmimeDefaultKey;
   else
-    signid = (PgpSignAs && *PgpSignAs) ? PgpSignAs : PgpDefaultKey;
+    signid = PgpSignAs ? PgpSignAs : PgpDefaultKey;
 
-  if (!signid || !*signid)
+  if (!signid)
     return 0;
 
   listctx = create_gpgme_context (for_smime);
@@ -2319,7 +2319,7 @@ static int pgp_gpgme_extract_keys (gpgme_data_t keydata, FILE** fp)
 
   if (legacy_api)
   {
-    snprintf (tmpdir, sizeof(tmpdir), "%s/mutt-gpgme-XXXXXX", Tempdir);
+    snprintf (tmpdir, sizeof(tmpdir), "%s/mutt-gpgme-XXXXXX", NONULL (Tempdir));
     if (!mkdtemp (tmpdir))
     {
       dprint (1, (debugfile, "Error creating temporary GPGME home\n"));
diff --git a/crypt.c b/crypt.c
index 98998280c8cd1c1c6a06713cefc6b461d804b376..85ab5fdff1db7bac5d1e42f059e9d78ed96c21ca 100644 (file)
--- a/crypt.c
+++ b/crypt.c
@@ -860,7 +860,7 @@ int crypt_get_keys (HEADER *msg, char **keylist, int oppenc_mode)
     }
   }
 
-  if (!oppenc_mode && self_encrypt && *self_encrypt)
+  if (!oppenc_mode && self_encrypt)
   {
     keylist_size = mutt_strlen (*keylist);
     safe_realloc (keylist, keylist_size + mutt_strlen (self_encrypt) + 2);
@@ -926,7 +926,7 @@ int mutt_should_hide_protected_subject (HEADER *h)
   if (option (OPTCRYPTPROTHDRSWRITE) &&
       (h->security & ENCRYPT) &&
       !(h->security & INLINE) &&
-      ProtHdrSubject && *ProtHdrSubject)
+      ProtHdrSubject)
     return 1;
 
   return 0;
index 32925f29d7d8d4b6ac019248a7728acbda6fc808..2054f42d52cebe7cab376cc335e928f081baae21 100644 (file)
@@ -2360,7 +2360,7 @@ int mutt_index_menu (void)
          if (!mutt_get_field (_("Enter macro stroke: "), buf, sizeof(buf),
                               MUTT_CLEAR) && buf[0])
          {
-           snprintf(str, sizeof(str), "%s%s", MarkMacroPrefix, buf);
+           snprintf(str, sizeof(str), "%s%s", NONULL (MarkMacroPrefix), buf);
            snprintf(macro, sizeof(macro),
                     "<search>~i \"%s\"\n", CURHDR->env->message_id);
             /* L10N: "message hotkey" is the key bindings menu description of a
index 36a855b344e3acef8c90789ce420a2cd458909a0..5c6397fcbca05876a9932802a72948a16b2da988 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -1546,7 +1546,7 @@ void mutt_decode_attachment (BODY *b, STATE *s)
   if (istext && s->flags & MUTT_CHARCONV)
   {
     char *charset = mutt_get_parameter ("charset", b->parameter);
-    if (!charset && AssumedCharset && *AssumedCharset)
+    if (!charset && AssumedCharset)
       charset = mutt_get_default_charset ();
     if (charset && Charset)
       cd = mutt_iconv_open (Charset, charset, MUTT_ICONV_HOOK_FROM);
index 2f601102ff5d471cbbb1cebfbdfb465bcb25acb9..466bb4d196e8335cdfb28834110466462da052c0 100644 (file)
--- a/hcache.c
+++ b/hcache.c
@@ -609,8 +609,7 @@ mutt_hcache_per_folder(const char *path, const char *folder,
   char* s;
   int ret, plen;
 #ifndef HAVE_ICONV
-  const char *chs = Charset && *Charset ? Charset :
-    mutt_get_default_charset ();
+  const char *chs = Charset ? Charset : mutt_get_default_charset ();
 #endif
 
   plen = mutt_strlen (path);
diff --git a/hook.c b/hook.c
index 3b339d8d64ab8c92ecbbc11fdf35d51badbaa1bd..1c96684aa66eabdf8fde4d3f45d7c12747d1f4a5 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -334,7 +334,7 @@ int mutt_parse_idxfmt_hook (BUFFER *buf, BUFFER *s, union pointer_long_t udata,
     goto out;
   }
 
-  if (DefaultHook && *DefaultHook)
+  if (DefaultHook)
     mutt_check_simple (pattern, DefaultHook);
 
   /* check to make sure that a matching hook doesn't already exist */
index 38512be7195b251217446ccc4ea897943e91b791..e32b5ab4caf9602708ade65134a30aa91fd5e98a 100644 (file)
@@ -57,7 +57,7 @@ int imap_authenticate (IMAP_DATA* idata)
   char* delim;
   int r = -1;
 
-  if (ImapAuthenticators && *ImapAuthenticators)
+  if (ImapAuthenticators)
   {
     /* Try user-specified list of authentication methods */
     methods = safe_strdup (ImapAuthenticators);
index 8c7ab9d0f5f977faa39b5d8f471ac7f138fb0b4d..a301e166320bdce8a9782ce309b24759e1bd15c8 100644 (file)
@@ -42,7 +42,7 @@ imap_auth_res_t imap_auth_oauth (IMAP_DATA* idata, const char* method)
     return IMAP_AUTH_UNAVAIL;
 
   /* If they did not explicitly request or configure oauth then fail quietly */
-  if (!(method || (ImapOauthRefreshCmd && *ImapOauthRefreshCmd)))
+  if (!(method || ImapOauthRefreshCmd))
       return IMAP_AUTH_UNAVAIL;
 
   mutt_message _("Authenticating (OAUTHBEARER)...");
diff --git a/init.c b/init.c
index 1a2b933af711f2acfeb1a496aef959a0bbea12dc..e02f12018e26a2bf55e6c6496854c0af985d86ae 100644 (file)
--- a/init.c
+++ b/init.c
@@ -2719,7 +2719,7 @@ static int source_rc (const char *rcfile, BUFFER *err)
   mutt_buffer_init (&token);
   while ((linebuf = mutt_read_line (linebuf, &buflen, f, &line, MUTT_CONT)) != NULL)
   {
-    conv=ConfigCharset && (*ConfigCharset) && Charset;
+    conv=ConfigCharset && Charset;
     if (conv)
     {
       currentline=safe_strdup(linebuf);
index 9c22f35f91741424fb2b221760bbbc3add44cc19..fbb0e5c4075157130795b9fbcae060e91ccf3eb0 100644 (file)
@@ -265,7 +265,7 @@ CONNECTION* mutt_conn_find (const CONNECTION* start, const ACCOUNT* account)
   conn->next = Connections;
   Connections = conn;
 
-  if (Tunnel && *Tunnel)
+  if (Tunnel)
     mutt_tunnel_socket_setup (conn);
   else if (account->flags & MUTT_ACCT_SSL)
   {
index 39b9e8d5c3664d70f6409143c2d2ff4ac737f28f..4350136daf876ea0626838e7143b216b8a8d4ab3 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -496,7 +496,7 @@ void _mutt_buffer_expand_path (BUFFER *src, int rx)
          mutt_buffer_strcpy (p, NONULL (Maildir));
        else
 #endif
-          if (Maildir && *Maildir && Maildir[strlen (Maildir) - 1] == '/')
+          if (Maildir && Maildir[strlen (Maildir) - 1] == '/')
             mutt_buffer_strcpy (p, NONULL (Maildir));
           else
             mutt_buffer_printf (p, "%s/", NONULL (Maildir));
diff --git a/parse.c b/parse.c
index 8f307aedcf01a6e269ba0065bd66332000176edc..6646fd03dbe7bcce315820319f976a7ee65dcc0d 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -183,7 +183,7 @@ static PARAMETER *parse_parameters (const char *s)
        s++;
        for (i=0; *s && i < sizeof (buffer) - 1; i++, s++)
        {
-         if (AssumedCharset && *AssumedCharset)
+         if (AssumedCharset)
           {
             /* As iso-2022-* has a character of '"' with non-ascii state,
             * ignore it. */
@@ -371,7 +371,7 @@ void mutt_parse_content_type (char *s, BODY *ct)
   if (ct->type == TYPETEXT)
   {
     if (!(pc = mutt_get_parameter ("charset", ct->parameter)))
-      mutt_set_parameter ("charset", (AssumedCharset && *AssumedCharset) ?
+      mutt_set_parameter ("charset", AssumedCharset ?
                           (const char *) mutt_get_default_charset ()
                           : "us-ascii", &ct->parameter);
   }
index c1ae7e391ea2dddc2afbd155e9b0c2ea34af6a8d..d9a73d02f59969ddcbe67065b9c272d179798428 100644 (file)
@@ -178,7 +178,7 @@ static pid_t pgp_invoke (FILE **pgpin, FILE **pgpout, FILE **pgperr,
   cctx.need_passphrase = need_passphrase;
   cctx.fname          = fname;
   cctx.sig_fname       = sig_fname;
-  if (PgpSignAs && *PgpSignAs)
+  if (PgpSignAs)
     cctx.signas               = PgpSignAs;
   else
     cctx.signas               = PgpDefaultKey;
@@ -273,7 +273,7 @@ void pgp_invoke_import (const char *fname)
 
   mutt_buffer_quote_filename (fnamebuf, fname);
   cctx.fname = mutt_b2s (fnamebuf);
-  if (PgpSignAs && *PgpSignAs)
+  if (PgpSignAs)
     cctx.signas               = PgpSignAs;
   else
     cctx.signas               = PgpDefaultKey;
index 1c3e1c1baf897eb1949798e4f151c45ae964d5b3..fd866ae0192957dac04e77d269171a7cec443fcb 100644 (file)
@@ -328,7 +328,7 @@ static pop_auth_res_t pop_auth_oauth (POP_DATA *pop_data, const char *method)
   int ret, len;
 
   /* If they did not explicitly request or configure oauth then fail quietly */
-  if (!(method || (PopOauthRefreshCmd && *PopOauthRefreshCmd)))
+  if (!(method || PopOauthRefreshCmd))
       return POP_A_UNAVAIL;
 
   mutt_message _("Authenticating (OAUTHBEARER)...");
@@ -406,7 +406,7 @@ int pop_authenticate (POP_DATA* pop_data)
   if (mutt_account_getuser (acct) || !acct->user[0])
     return -3;
 
-  if (PopAuthenticators && *PopAuthenticators)
+  if (PopAuthenticators)
   {
     /* Try user-specified list of authentication methods */
     methods = safe_strdup (PopAuthenticators);
index 50ff84697ebc77ea2f47fb6657e5a14106578a57..228c5671aaf8dddfd192dc8d6ab7a2263b3e6df5 100644 (file)
--- a/rfc1524.c
+++ b/rfc1524.c
@@ -433,7 +433,7 @@ int rfc1524_mailcap_lookup (BODY *a, char *type, rfc1524_entry *entry, int opt)
    * and overridden by the MAILCAPS environment variable, and, just to be nice,
    * we'll make it specifiable in .muttrc
    */
-  if (!curr || !*curr)
+  if (!curr)
   {
     mutt_error _("No mailcap path specified");
     return 0;
index f2f333d304ab3b046e26c3390dd42a5c86950383..7ed08c509782c1f13460820271729a8f1cf8977e 100644 (file)
--- a/rfc2047.c
+++ b/rfc2047.c
@@ -593,7 +593,7 @@ void _rfc2047_encode_string (char **pd, int encode_specials, int col)
     return;
 
   charsets = SendCharset;
-  if (!charsets || !*charsets)
+  if (!charsets)
     charsets = "utf-8";
 
   rfc2047_encode (*pd, strlen (*pd), col,
@@ -810,7 +810,7 @@ static void convert_and_add_text (BUFFER *d, const char *text, size_t len)
 {
   char *t;
 
-  if (AssumedCharset && *AssumedCharset)
+  if (AssumedCharset)
   {
     t = safe_malloc (len + 1);
     strfcpy (t, text, len + 1);
@@ -950,7 +950,7 @@ void rfc2047_decode_adrlist (ADDRESS *a)
   while (a)
   {
     if (a->personal && ((strstr (a->personal, "=?") != NULL) ||
-                       (AssumedCharset && *AssumedCharset)))
+                       AssumedCharset))
       rfc2047_decode (&a->personal);
     else if (a->group && a->mailbox && (strstr (a->mailbox, "=?") != NULL))
       rfc2047_decode (&a->mailbox);
index e3d8e1a5d279fd24f2c8b919e0d585020cc2c037..68d051cac9efb480891c00bc2c42c6182347025d 100644 (file)
--- a/rfc2231.c
+++ b/rfc2231.c
@@ -116,7 +116,7 @@ void rfc2231_decode_parameters (PARAMETER **headp)
 
       if (option (OPTRFC2047PARAMS) && p->value && strstr (p->value, "=?"))
        rfc2047_decode (&p->value);
-      else if (AssumedCharset && *AssumedCharset)
+      else if (AssumedCharset)
         convert_nonmime_string (&p->value);
 
       *last = p;
diff --git a/send.c b/send.c
index 2471d242ace7950079c22a971885be8ebd69ea09..d45141c308783c4a5b1c8141c15bc45e78cc7d20 100644 (file)
--- a/send.c
+++ b/send.c
@@ -1455,7 +1455,7 @@ static int postpone_message (HEADER *msg, HEADER *cur, char *fcc, int flags)
   int is_signed;
   BODY *clear_content = NULL;
 
-  if (!(Postponed && *Postponed))
+  if (!Postponed)
   {
     mutt_error _("Cannot postpone.  $postponed is unset");
     return -1;
@@ -1472,10 +1472,10 @@ static int postpone_message (HEADER *msg, HEADER *cur, char *fcc, int flags)
       encrypt_as = PgpDefaultKey;
     else if ((WithCrypto & APPLICATION_SMIME) && (msg->security & APPLICATION_SMIME))
       encrypt_as = SmimeDefaultKey;
-    if (!(encrypt_as && *encrypt_as))
+    if (!encrypt_as)
       encrypt_as = PostponeEncryptAs;
 
-    if (encrypt_as && *encrypt_as)
+    if (encrypt_as)
     {
       is_signed = msg->security & SIGN;
       if (is_signed)
index 46212a2fee51067d56e542ebbad5a7273a76dc6f..331cc2b26cb0ae6c803a5b966b861ac262893d61 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -915,8 +915,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY *b)
   if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset))
   {
     char *chs = mutt_get_parameter ("charset", b->parameter);
-    char *fchs = b->use_disp ? ((AttachCharset && *AttachCharset) ?
-                                AttachCharset : Charset) : Charset;
+    char *fchs = b->use_disp ? (AttachCharset ? AttachCharset : Charset) : Charset;
     if (Charset && (chs || SendCharset) &&
         convert_file_from_to (fp, fchs, chs ? chs : SendCharset,
                               &fromcode, &tocode, info) != (size_t)(-1))
@@ -1407,8 +1406,7 @@ BODY *mutt_make_file_attach (const char *path)
   att = mutt_new_body ();
   att->filename = safe_strdup (path);
 
-  if (MimeTypeQueryCmd && *MimeTypeQueryCmd &&
-      option (OPTMIMETYPEQUERYFIRST))
+  if (MimeTypeQueryCmd && option (OPTMIMETYPEQUERYFIRST))
     run_mime_type_query (att);
 
   /* Attempt to determine the appropriate content-type based on the filename
@@ -1418,7 +1416,7 @@ BODY *mutt_make_file_attach (const char *path)
     mutt_lookup_mime_type (att, path);
 
   if (!att->subtype &&
-      MimeTypeQueryCmd && *MimeTypeQueryCmd &&
+      MimeTypeQueryCmd &&
       !option (OPTMIMETYPEQUERYFIRST))
     run_mime_type_query (att);
 
@@ -2856,7 +2854,7 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post,
     if (hdr->security & SIGN)
     {
       fputc ('S', msg->fp);
-      if (PgpSignAs && *PgpSignAs)
+      if (PgpSignAs)
         fprintf (msg->fp, "<%s>", PgpSignAs);
     }
     if (hdr->security & INLINE)
@@ -2872,7 +2870,7 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post,
     if (hdr->security & ENCRYPT)
     {
       fputc ('E', msg->fp);
-      if (SmimeCryptAlg && *SmimeCryptAlg)
+      if (SmimeCryptAlg)
         fprintf (msg->fp, "C<%s>", SmimeCryptAlg);
     }
     if (hdr->security & OPPENCRYPT)
@@ -2880,7 +2878,7 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post,
     if (hdr->security & SIGN)
     {
       fputc ('S', msg->fp);
-      if (SmimeSignAs && *SmimeSignAs)
+      if (SmimeSignAs)
         fprintf (msg->fp, "<%s>", SmimeSignAs);
     }
     if (hdr->security & INLINE)
diff --git a/smime.c b/smime.c
index c52f68f873e2f5faf99548654f88eaee85facb4d..a890912110180f41b34da219f4fa1fb955dc9a3c 100644 (file)
--- a/smime.c
+++ b/smime.c
@@ -859,7 +859,7 @@ void smime_getkeys (ENVELOPE *env)
   ADDRESS *t;
   int found = 0;
 
-  if (option (OPTSDEFAULTDECRYPTKEY) && SmimeDefaultKey && *SmimeDefaultKey)
+  if (option (OPTSDEFAULTDECRYPTKEY) && SmimeDefaultKey)
   {
     snprintf (SmimeKeyToUse, sizeof (SmimeKeyToUse), "%s/%s",
              NONULL (SmimeKeys), SmimeDefaultKey);
@@ -1545,8 +1545,8 @@ BODY *smime_sign_message (BODY *a )
   char *intermediates;
   char *micalg;
 
-  signas = (SmimeSignAs && *SmimeSignAs) ? SmimeSignAs : SmimeDefaultKey;
-  if (!signas || !*signas)
+  signas = SmimeSignAs ? SmimeSignAs : SmimeDefaultKey;
+  if (!signas)
   {
     mutt_error _("Can't sign: No key specified. Use Sign As.");
     return NULL;
diff --git a/smtp.c b/smtp.c
index 16223d3195831433994c43ca22f9ce89c7aaa98b..1e80d5e6a76e10bac5673ff608c36b84946b24ee 100644 (file)
--- a/smtp.c
+++ b/smtp.c
@@ -508,7 +508,7 @@ static int smtp_auth (CONNECTION* conn)
 {
   int r = SMTP_AUTH_UNAVAIL;
 
-  if (SmtpAuthenticators && *SmtpAuthenticators)
+  if (SmtpAuthenticators)
   {
     char* methods = safe_strdup (SmtpAuthenticators);
     char* method;