From: Ralph Corderoy Date: Sat, 13 May 2017 12:13:18 +0000 (+0100) Subject: Add FENDNULL(s): fends off NULL by giving an empty string instead. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/042f5bed7ff3e5b34ff3166951a7b98bf6bbf105 Add FENDNULL(s): fends off NULL by giving an empty string instead. Use it in place of all the `foo->bar_xyzzy ? foo->bar_xyzzy : ""'. Avoids the reader having to check first two of the ternary operands are the same. --- diff --git a/config/config.c b/config/config.c index 7d9f2633..633293e2 100644 --- a/config/config.c +++ b/config/config.c @@ -56,7 +56,7 @@ etcpath (char *file) } } - snprintf (epath, sizeof(epath), "%s/%s", pp, cp ? cp : ""); + snprintf (epath, sizeof(epath), "%s/%s", pp, FENDNULL(cp)); if (cp) *--cp = '/'; diff --git a/h/mh.h b/h/mh.h index e549b2d4..77671f8d 100644 --- a/h/mh.h +++ b/h/mh.h @@ -48,6 +48,9 @@ typedef unsigned char boolean; /* not int so we can pack in a structure */ * terminating NUL. */ #define LEN(s) (sizeof (s) - 1) +/* FENDNULL fends off NULL by giving an empty string instead. */ +#define FENDNULL(s) ((s) ? (s) : "") + /* * char array that keeps track of size in both bytes and characters * Usage note: diff --git a/mts/smtp/smtp.c b/mts/smtp/smtp.c index 003aa6a2..b09fde33 100644 --- a/mts/smtp/smtp.c +++ b/mts/smtp/smtp.c @@ -493,7 +493,7 @@ sm_wadr (char *mbox, char *host, char *path) { switch (smtalk (SM_RCPT, host && *host ? "RCPT TO:<%s%s@%s>" : "RCPT TO:<%s%s>", - path ? path : "", mbox, host)) { + FENDNULL(path), mbox, host)) { case 250: case 251: sm_addrs++; diff --git a/sbr/addrsbr.c b/sbr/addrsbr.c index 68bb6dec..1e435502 100644 --- a/sbr/addrsbr.c +++ b/sbr/addrsbr.c @@ -89,7 +89,7 @@ getname (const char *addrs) pers = mbox = host = route = grp = note = NULL; err[0] = '\0'; - if ((ap = getadrx (addrs ? addrs : "", eai)) == NULL) { + if ((ap = getadrx (FENDNULL(addrs), eai)) == NULL) { return NULL; } @@ -216,7 +216,7 @@ mnfree (struct mailname *mp) } -#define empty(s) ((s) ? (s) : "") +#define empty(s) FENDNULL(s) char * auxformat (struct mailname *mp, int extras) @@ -225,7 +225,7 @@ auxformat (struct mailname *mp, int extras) static char buffer[BUFSIZ]; if (mp->m_nohost) - strncpy (addr, mp->m_mbox ? mp->m_mbox : "", sizeof(addr)); + strncpy (addr, FENDNULL(mp->m_mbox), sizeof(addr)); else if (mp->m_type != UUCPHOST) { @@ -355,8 +355,8 @@ ismymbox (struct mailname *np) for (mp = &mq; mp; mp = mp->m_next) { fprintf (stderr, "Local- or Alternate-Mailbox: text=\"%s\" " "mbox=\"%s\" host=\"%s\" %s\n", - mp->m_text ? mp->m_text : "", mp->m_mbox, - mp->m_host ? mp->m_host : "", + FENDNULL(mp->m_text), mp->m_mbox, + FENDNULL(mp->m_host), snprintb (buffer, sizeof(buffer), (unsigned) mp->m_type, WBITS)); } diff --git a/sbr/context_del.c b/sbr/context_del.c index 62585f9e..efe5e410 100644 --- a/sbr/context_del.c +++ b/sbr/context_del.c @@ -19,7 +19,7 @@ context_del (char *key) struct node *np, *pp; for (np = m_defs, pp = NULL; np; pp = np, np = np->n_next) { - if (!strcasecmp (np->n_name ? np->n_name : "", key ? key : "")) { + if (!strcasecmp (FENDNULL(np->n_name), FENDNULL(key))) { if (!np->n_context) inform("bug: context_del(key=\"%s\"), continuing...", np->n_name); if (pp) diff --git a/sbr/context_find.c b/sbr/context_find.c index 3a7b920d..4d89fbc5 100644 --- a/sbr/context_find.c +++ b/sbr/context_find.c @@ -14,7 +14,7 @@ context_find (const char *str) struct node *np; for (np = m_defs; np; np = np->n_next) - if (!strcasecmp (np->n_name ? np->n_name : "", str ? str : "")) + if (!strcasecmp (FENDNULL(np->n_name), FENDNULL(str))) return (np->n_field); return NULL; diff --git a/sbr/context_replace.c b/sbr/context_replace.c index b97162ba..1027dcf6 100644 --- a/sbr/context_replace.c +++ b/sbr/context_replace.c @@ -33,7 +33,7 @@ context_replace (char *key, char *value) * this key, and replace its value if found. */ for (np = m_defs;; np = np->n_next) { - if (!strcasecmp (np->n_name ? np->n_name : "", key ? key : "")) { + if (!strcasecmp (FENDNULL(np->n_name), FENDNULL(key))) { if (strcmp (value, np->n_field)) { if (!np->n_context) inform("bug: context_replace(key=\"%s\",value=\"%s\"), continuing...", key, value); diff --git a/sbr/fmt_compile.c b/sbr/fmt_compile.c index 33f34efe..b0ce6462 100644 --- a/sbr/fmt_compile.c +++ b/sbr/fmt_compile.c @@ -998,7 +998,7 @@ fmt_findcasecomp(char *component) struct comp *cm; for (cm = wantcomp[CHASH(component)]; cm; cm = cm->c_next) - if (strcasecmp(component, cm->c_name ? cm->c_name : "") == 0) + if (strcasecmp(component, FENDNULL(cm->c_name)) == 0) break; return cm; @@ -1050,7 +1050,7 @@ fmt_addcomptext(char *component, char *text) char *cp; while (cptr) { - if (strcasecmp(component, cptr->c_name ? cptr->c_name : "") == 0) { + if (strcasecmp(component, FENDNULL(cptr->c_name)) == 0) { found++; if (! cptr->c_text) { cptr->c_text = getcpy(text); @@ -1085,7 +1085,7 @@ fmt_appendcomp(int bucket, char *component, char *text) if (bucket != -1) { for (cptr = wantcomp[bucket]; cptr; cptr = cptr->c_next) - if (strcasecmp(component, cptr->c_name ? cptr->c_name : "") == 0) + if (strcasecmp(component, FENDNULL(cptr->c_name)) == 0) cptr->c_text = add(text, cptr->c_text); } } diff --git a/sbr/mf.c b/sbr/mf.c index e0abb293..b6c72912 100644 --- a/sbr/mf.c +++ b/sbr/mf.c @@ -163,7 +163,7 @@ getadrx (const char *addrs, int eai) err[0] = 0; if (dp == NULL) { - dp = cp = strdup (addrs ? addrs : ""); + dp = cp = strdup (FENDNULL(addrs)); glevel = 0; } else diff --git a/sbr/mime_type.c b/sbr/mime_type.c index bcc1c392..379c248d 100644 --- a/sbr/mime_type.c +++ b/sbr/mime_type.c @@ -68,7 +68,7 @@ mime_type(const char *file_name) { if ((p = strrchr(file_name, '.')) != NULL) { for (np = m_defs; np; np = np->n_next) { if (strncasecmp(np->n_name, "mhshow-suffix-", 14) == 0 && - strcasecmp(p, np->n_field ? np->n_field : "") == 0) { + strcasecmp(p, FENDNULL(np->n_field)) == 0) { content_type = strdup(np->n_name + 14); break; } diff --git a/sbr/seq_print.c b/sbr/seq_print.c index 24f669a1..ce3c45fb 100644 --- a/sbr/seq_print.c +++ b/sbr/seq_print.c @@ -7,7 +7,7 @@ #include -#define empty(s) ((s) ? (s) : "") +#define empty(s) FENDNULL(s) /* * Print all the sequences in a folder diff --git a/uip/ali.c b/uip/ali.c index fe57ef3e..a75edf36 100644 --- a/uip/ali.c +++ b/uip/ali.c @@ -217,10 +217,10 @@ print_usr (char *s, int list) while ((cp = getname (pp))) { if ((np = getm (cp, NULL, 0, NULL, 0)) == NULL) continue; - if (!strcasecmp (mp->m_host ? mp->m_host : "", - np->m_host ? np->m_host : "") && - !strcasecmp (mp->m_mbox ? mp->m_mbox : "", - np->m_mbox ? np->m_mbox : "")) { + if (!strcasecmp (FENDNULL(mp->m_host), + FENDNULL(np->m_host)) && + !strcasecmp (FENDNULL(mp->m_mbox), + FENDNULL(np->m_mbox))) { vp = vp ? add (ak->ak_name, add (",", vp)) : getcpy (ak->ak_name); mnfree (np); diff --git a/uip/fmttest.c b/uip/fmttest.c index 5f52fdc3..19df3107 100644 --- a/uip/fmttest.c +++ b/uip/fmttest.c @@ -1302,10 +1302,10 @@ insert (struct mailname *np) return 0; for (mp = &mq; mp->m_next; mp = mp->m_next) { - if (!strcasecmp (np->m_host ? np->m_host : "", - mp->m_next->m_host ? mp->m_next->m_host : "") && - !strcasecmp (np->m_mbox ? np->m_mbox : "", - mp->m_next->m_mbox ? mp->m_next->m_mbox : "")) + if (!strcasecmp (FENDNULL(np->m_host), + FENDNULL(mp->m_next->m_host)) && + !strcasecmp (FENDNULL(np->m_mbox), + FENDNULL(mp->m_next->m_mbox))) return 0; } if (!ccme && ismymbox (np)) diff --git a/uip/folder.c b/uip/folder.c index bfeee8fa..23aea0b7 100644 --- a/uip/folder.c +++ b/uip/folder.c @@ -335,7 +335,8 @@ main (int argc, char **argv) if (msg) inform("no folder given for message %s, continuing...", msg); readonly_folders (); /* do any readonly folders */ - strncpy (folder, (cp = context_find (pfolder)) ? cp : "", sizeof(folder)); + cp = context_find(pfolder); + strncpy (folder, FENDNULL(cp), sizeof(folder)); crawl_folders (".", get_folder_info_callback, NULL); } else { strncpy (folder, argfolder, sizeof(folder)); diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index 412f871e..b5d88a3f 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -2066,7 +2066,7 @@ set_disposition (CT ct) { "continuing...", invo_name, ct->c_ctinfo.ci_type, ct->c_ctinfo.ci_subtype ? "/" : "", - ct->c_ctinfo.ci_subtype ? ct->c_ctinfo.ci_subtype : "", + FENDNULL(ct->c_ctinfo.ci_subtype), cp); } @@ -2231,7 +2231,7 @@ expand_pseudoheader (CT ct, CT *text_plain_ct, struct multipart *m, /* reply_file is used to pass the output of the convert. */ reply_file = getcpy (m_mktemp2 (NULL, invo_name, NULL, NULL)); convert_command = - concat (convert, " ", argstring ? argstring : "", " >", reply_file, + concat (convert, " ", FENDNULL(argstring), " >", reply_file, NULL); /* Convert here . . . */ diff --git a/uip/mhfixmsg.c b/uip/mhfixmsg.c index acdb9d7a..615575b6 100644 --- a/uip/mhfixmsg.c +++ b/uip/mhfixmsg.c @@ -870,7 +870,7 @@ replace_boundary (CT ct, char *file, char *boundary) { strlen(new_ctline) + 1, ct->c_ctinfo.ci_first_pm, NULL, 0); fprintf (fpout, "%s:%s%s\n", np, new_ctline, - new_params ? new_params : ""); + FENDNULL(new_params)); free(new_ctline); mh_xfree(new_params); } @@ -1657,7 +1657,7 @@ reformat_part (CT ct, char *file, char *type, char *subtype, int c_type) { if (strchr (cf, '>')) { inform("'>' prohibited in \"%s\",\nplease fix your " "%s-format-%s/%s profile entry", cf, invo_name, type, - subtype ? subtype : ""); + FENDNULL(subtype)); return NOTOK; } @@ -1774,7 +1774,7 @@ build_multipart_alt (CT first_alt, CT new_part, int type, int subtype) { snprintf (buffer2, sizeof buffer2, "%d", serial); boundary = concat (boundary_prefix, - first_alt->c_partno ? first_alt->c_partno : "", + FENDNULL(first_alt->c_partno), "-", buffer2, NULL); } } @@ -2017,8 +2017,7 @@ decode_text_parts (CT ct, int encoding, const char *decodetypes, report (NULL, ct->c_partno, ct->c_file, "will not decode%s because it is binary (%s)", ct->c_partno ? "" - : ct->c_ctline ? ct->c_ctline - : "", + : (FENDNULL(ct->c_ctline)), reason); } (void) m_unlink (ct->c_cefile.ce_file); @@ -2032,8 +2031,7 @@ decode_text_parts (CT ct, int encoding, const char *decodetypes, report (NULL, ct->c_partno, ct->c_file, "will not decode%s because it is 8bit", ct->c_partno ? "" - : ct->c_ctline ? ct->c_ctline - : ""); + : (FENDNULL(ct->c_ctline))); } (void) m_unlink (ct->c_cefile.ce_file); free (ct->c_cefile.ce_file); @@ -2052,7 +2050,7 @@ decode_text_parts (CT ct, int encoding, const char *decodetypes, ++*message_mods; if (verbosw) { report (NULL, ct->c_partno, ct->c_file, "decode%s", - ct->c_ctline ? ct->c_ctline : ""); + FENDNULL(ct->c_ctline)); } if (lf_line_endings) { strip_crs (ct, message_mods); @@ -2809,7 +2807,7 @@ report (char *what, char *partno, char *filename, char *message, ...) { if (verbosw) { va_start (args, message); fmt = concat (filename, partno ? " part " : ", ", - partno ? partno : "", partno ? ", " : "", message, NULL); + FENDNULL(partno), partno ? ", " : "", message, NULL); advertise (what, NULL, fmt, args); diff --git a/uip/mhlistsbr.c b/uip/mhlistsbr.c index 452c7fd4..42b04ae2 100644 --- a/uip/mhlistsbr.c +++ b/uip/mhlistsbr.c @@ -133,7 +133,7 @@ list_switch (CT ct, int toplevel, int realsize, int verbose, int debug, } -#define empty(s) ((s) ? (s) : "") +#define empty(s) FENDNULL(s) /* * Method for listing information about a simple/generic content @@ -452,7 +452,7 @@ list_encoding (CT ct) fprintf (stderr, " decoded fp 0x%x file \"%s\"\n", (unsigned int)(unsigned long) ce->ce_fp, - ce->ce_file ? ce->ce_file : ""); + FENDNULL(ce->ce_file)); return OK; } diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index 6dd1850d..ea0c7d32 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -1019,13 +1019,13 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec) continue; for (c2 = fmthd; c2; c2 = c2->c_next) - if (!strcasecmp (c2->c_name ? c2->c_name : "", name)) + if (!strcasecmp (FENDNULL(c2->c_name), name)) break; c1 = NULL; if (!((c3 = c2 ? c2 : &global)->c_flags & SPLIT)) for (c1 = msghd; c1; c1 = c1->c_next) - if (!strcasecmp (c1->c_name ? c1->c_name : "", - c3->c_name ? c3->c_name : "")) { + if (!strcasecmp (FENDNULL(c1->c_name), + FENDNULL(c3->c_name))) { c1->c_text = mcomp_add (c1->c_flags, buf, c1->c_text); break; @@ -1085,8 +1085,8 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec) continue; } for (c2 = msghd; c2; c2 = c2->c_next) - if (!strcasecmp (c2->c_name ? c2->c_name : "", - c1->c_name ? c1->c_name : "")) { + if (!strcasecmp (FENDNULL(c2->c_name), + FENDNULL(c1->c_name))) { putcomp (c1, c2, ONECOMP); if (!(c1->c_flags & SPLIT)) break; @@ -1590,7 +1590,7 @@ putch (char ch, unsigned long flags) putch ('\n', flags); if (ovoff > 0) lm = ovoff; - putstr (ovtxt ? ovtxt : "", flags); + putstr (FENDNULL(ovtxt), flags); putch (ch, flags); return; } diff --git a/uip/mhparam.c b/uip/mhparam.c index 4d8407d1..14988847 100644 --- a/uip/mhparam.c +++ b/uip/mhparam.c @@ -228,7 +228,7 @@ main(int argc, char **argv) * value (as determined after context is read). */ for (ps = procs; ps->p_name; ps++) - printf ("%s: %s\n", ps->p_name, *ps->p_field ? *ps->p_field : ""); + printf ("%s: %s\n", ps->p_name, FENDNULL(*ps->p_field)); } diff --git a/uip/mhshowsbr.c b/uip/mhshowsbr.c index 2ef4734a..1e3a4ba4 100644 --- a/uip/mhshowsbr.c +++ b/uip/mhshowsbr.c @@ -370,7 +370,7 @@ show_content_aux (CT ct, int alternate, char *cp, char *cracked, struct format * char *charset = content_charset (ct); inform("unable to convert character set%s%s from %s, continuing...", ct->c_partno ? " of part " : "", - ct->c_partno ? ct->c_partno : "", + FENDNULL(ct->c_partno), charset); free (charset); } diff --git a/uip/post.c b/uip/post.c index 1323e19d..3c9a61e8 100644 --- a/uip/post.c +++ b/uip/post.c @@ -1211,7 +1211,7 @@ get_header (char *header, struct headers *table) struct headers *h; for (h = table; h->value; h++) - if (!strcasecmp (header ? header : "", h->value ? h->value : "")) + if (!strcasecmp (FENDNULL(header), FENDNULL(h->value))) return (h - table); return NOTOK; @@ -1312,10 +1312,10 @@ insert (struct mailname *np) : &netaddrs; mp->m_next; mp = mp->m_next) - if (!strcasecmp (np->m_host ? np->m_host : "", - mp->m_next->m_host ? mp->m_next->m_host : "") && - !strcasecmp (np->m_mbox ? np->m_mbox : "", - mp->m_next->m_mbox ? mp->m_next->m_mbox : "") && + if (!strcasecmp (FENDNULL(np->m_host), + FENDNULL(mp->m_next->m_host)) && + !strcasecmp (FENDNULL(np->m_mbox), + FENDNULL(mp->m_next->m_mbox)) && np->m_bcc == mp->m_next->m_bcc) return 0; @@ -1339,7 +1339,7 @@ pl (void) printf ("\nnet:\t"); for (mp = netaddrs.m_next; mp; mp = mp->m_next) - printf ("%s%s@%s%s%s", mp->m_path ? mp->m_path : "", + printf ("%s%s@%s%s%s", FENDNULL(mp->m_path), mp->m_mbox, mp->m_host, mp->m_bcc ? "[BCC]" : "", mp->m_next ? ",\n\t" : ""); diff --git a/uip/replsbr.c b/uip/replsbr.c index fe79c295..3f40a614 100644 --- a/uip/replsbr.c +++ b/uip/replsbr.c @@ -384,10 +384,10 @@ insert (struct mailname *np) return 0; for (mp = &mq; mp->m_next; mp = mp->m_next) { - if (!strcasecmp (np->m_host ? np->m_host : "", - mp->m_next->m_host ? mp->m_next->m_host : "") && - !strcasecmp (np->m_mbox ? np->m_mbox : "", - mp->m_next->m_mbox ? mp->m_next->m_mbox : "")) + if (!strcasecmp (FENDNULL(np->m_host), + FENDNULL(mp->m_next->m_host)) && + !strcasecmp (FENDNULL(np->m_mbox), + FENDNULL(mp->m_next->m_mbox))) return 0; } if (!ccme && ismymbox (np))