From af9b66336bdbd198f3b1e7bca82e3d1278f27664 Mon Sep 17 00:00:00 2001 From: Ralph Corderoy Date: Tue, 26 Sep 2017 14:32:08 +0100 Subject: [PATCH] Replace getcpy(f()) calls with mh_xstrdup() when f() can't be NULL. And comment a few functions as never returning NULL along the way. --- config/config.c | 1 + sbr/arglist.c | 2 +- sbr/context_read.c | 3 ++- sbr/getfolder.c | 1 + sbr/m_draft.c | 1 + sbr/m_maildir.c | 2 +- sbr/r1bindex.c | 1 + uip/anno.c | 2 +- uip/folder.c | 4 ++-- uip/forw.c | 4 ++-- uip/inc.c | 2 +- uip/install-mh.c | 2 +- uip/mhbuild.c | 2 +- uip/mhlist.c | 2 +- uip/mhn.c | 4 ++-- uip/mhshow.c | 4 ++-- uip/mhshowsbr.c | 2 +- uip/mhstore.c | 2 +- uip/refile.c | 2 +- uip/repl.c | 4 ++-- uip/send.c | 6 +++--- uip/show.c | 4 ++-- uip/whatnowsbr.c | 4 ++-- uip/whom.c | 4 ++-- 24 files changed, 35 insertions(+), 30 deletions(-) diff --git a/config/config.c b/config/config.c index fa3df3bd..2511472e 100644 --- a/config/config.c +++ b/config/config.c @@ -23,6 +23,7 @@ * 3) Next, check in nmh Mail directory. * 4) Next, check in nmh `etc' directory. * + * Does not return NULL. */ char * diff --git a/sbr/arglist.c b/sbr/arglist.c index 9425439a..026da19e 100644 --- a/sbr/arglist.c +++ b/sbr/arglist.c @@ -57,7 +57,7 @@ argsplit(char *command, char **file, int *argp) */ if (!space && !metachar) { - argvarray[0] = getcpy(r1bindex(command, '/')); + argvarray[0] = mh_xstrdup(r1bindex(command, '/')); argvarray[1] = NULL; *file = mh_xstrdup(command); if (argp) diff --git a/sbr/context_read.c b/sbr/context_read.c index a8d14202..f899624e 100644 --- a/sbr/context_read.c +++ b/sbr/context_read.c @@ -26,6 +26,7 @@ #include "m_maildir.h" #include "makedir.h" #include /* structure for getpwuid() results */ +#include "h/utils.h" void context_read (void) @@ -137,7 +138,7 @@ context_read (void) return; } - ctxpath = getcpy (m_maildir (cp)); + ctxpath = mh_xstrdup(m_maildir(cp)); if ((ib = lkfopendata (ctxpath, "r", &failed_to_lock))) { readconfig(NULL, ib, cp, 1); diff --git a/sbr/getfolder.c b/sbr/getfolder.c index 15ee8a70..d1a298bf 100644 --- a/sbr/getfolder.c +++ b/sbr/getfolder.c @@ -8,6 +8,7 @@ #include +/* Does not return NULL. */ char * getfolder(int wantcurrent) { diff --git a/sbr/m_draft.c b/sbr/m_draft.c index a09bf060..ebf7ef7e 100644 --- a/sbr/m_draft.c +++ b/sbr/m_draft.c @@ -11,6 +11,7 @@ #include "h/done.h" +/* Does not return NULL. */ char * m_draft (char *folder, char *msg, int use, int *isdf) { diff --git a/sbr/m_maildir.c b/sbr/m_maildir.c index daf84a73..103d02c6 100644 --- a/sbr/m_maildir.c +++ b/sbr/m_maildir.c @@ -50,7 +50,7 @@ m_mailpath (char *folder) && strcmp (folder, DOTDOT) && !has_prefix(folder, PWD)) { strncpy (maildir, mailfold, sizeof(maildir)); /* preserve... */ - cp = getcpy (m_maildir (folder)); + cp = mh_xstrdup(m_maildir(folder)); strncpy (mailfold, maildir, sizeof(mailfold)); } else { cp = path (folder, TFOLDER); diff --git a/sbr/r1bindex.c b/sbr/r1bindex.c index 7dcabb50..0fd8d51d 100644 --- a/sbr/r1bindex.c +++ b/sbr/r1bindex.c @@ -10,6 +10,7 @@ #include +/* Does not return NULL. */ char * r1bindex(char *str, int chr) { diff --git a/uip/anno.c b/uip/anno.c index 77ecc10b..1c4e0cae 100644 --- a/uip/anno.c +++ b/uip/anno.c @@ -210,7 +210,7 @@ main (int argc, char **argv) if (msgs.size != 0) adios(NULL, "can only have message numbers or -draft."); - draft = getcpy(m_draft(folder, NULL, 1, &isdf)); + draft = mh_xstrdup(m_draft(folder, NULL, 1, &isdf)); make_comp(&comp); diff --git a/uip/folder.c b/uip/folder.c index 001c3429..3989a42c 100644 --- a/uip/folder.c +++ b/uip/folder.c @@ -258,7 +258,7 @@ main (int argc, char **argv) } else { adios (NULL, "no other folder"); } - for (cp = getcpy (getfolder (1)); *ap; ap++) + for (cp = mh_xstrdup(getfolder(1)); *ap; ap++) cp = add (*ap, add (" ", cp)); free (dp); context_replace (stack, cp); /* update folder stack */ @@ -267,7 +267,7 @@ main (int argc, char **argv) context_replace (stack, (cp = context_find (stack)) ? concat (getfolder (1), " ", cp, NULL) - : getcpy (getfolder (1))); + : mh_xstrdup(getfolder(1))); } } diff --git a/uip/forw.c b/uip/forw.c index 288e85a0..6ec53be3 100644 --- a/uip/forw.c +++ b/uip/forw.c @@ -179,7 +179,7 @@ main (int argc, char **argv) case FILTSW: if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); - filter = getcpy (etcpath (cp)); + filter = mh_xstrdup(etcpath(cp)); mime = 0; continue; case FORMSW: @@ -188,7 +188,7 @@ main (int argc, char **argv) continue; case FRMTSW: - filter = getcpy (etcpath (mhlforward)); + filter = mh_xstrdup(etcpath(mhlforward)); continue; case NFRMTSW: filter = NULL; diff --git a/uip/inc.c b/uip/inc.c index e824ea37..552d7932 100644 --- a/uip/inc.c +++ b/uip/inc.c @@ -249,7 +249,7 @@ main (int argc, char **argv) case AUDSW: if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); - audfile = getcpy (m_maildir (cp)); + audfile = mh_xstrdup(m_maildir(cp)); continue; case NAUDSW: audfile = NULL; diff --git a/uip/install-mh.c b/uip/install-mh.c index 2470c3ef..0d5b3bb0 100644 --- a/uip/install-mh.c +++ b/uip/install-mh.c @@ -192,7 +192,7 @@ query: fclose (in); } - ctxpath = getcpy (m_maildir (context = "context")); + ctxpath = mh_xstrdup(m_maildir(context = "context")); /* Initialize current folder to default */ context_replace (pfolder, defaultfolder); diff --git a/uip/mhbuild.c b/uip/mhbuild.c index b6f26eb9..07074d75 100644 --- a/uip/mhbuild.c +++ b/uip/mhbuild.c @@ -305,7 +305,7 @@ main (int argc, char **argv) /* Check for private cache location */ if (!(cache_private = context_find (nmhprivcache))) cache_private = ".cache"; - cache_private = getcpy (m_maildir (cache_private)); + cache_private = mh_xstrdup(m_maildir(cache_private)); if (!context_find ("path")) free (path ("./", TFOLDER)); diff --git a/uip/mhlist.c b/uip/mhlist.c index aa304e68..9e4b9570 100644 --- a/uip/mhlist.c +++ b/uip/mhlist.c @@ -229,7 +229,7 @@ do_cache: /* Check for private cache location */ if (!(cache_private = context_find (nmhprivcache))) cache_private = ".cache"; - cache_private = getcpy (m_maildir (cache_private)); + cache_private = mh_xstrdup(m_maildir(cache_private)); if (!context_find ("path")) free (path ("./", TFOLDER)); diff --git a/uip/mhn.c b/uip/mhn.c index 94f25ace..a5b4a274 100644 --- a/uip/mhn.c +++ b/uip/mhn.c @@ -248,7 +248,7 @@ do_cache: if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); free(formsw); - formsw = getcpy (etcpath (cp)); + formsw = mh_xstrdup(etcpath(cp)); continue; /* @@ -334,7 +334,7 @@ do_cache: /* Check for private cache location */ if (!(cache_private = context_find (nmhprivcache))) cache_private = ".cache"; - cache_private = getcpy (m_maildir (cache_private)); + cache_private = mh_xstrdup(m_maildir(cache_private)); /* * Cache the current directory before we do any chdirs()'s. diff --git a/uip/mhshow.c b/uip/mhshow.c index d3b8504e..13fa3b7c 100644 --- a/uip/mhshow.c +++ b/uip/mhshow.c @@ -209,7 +209,7 @@ do_cache: if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); free(formsw); - formsw = getcpy (etcpath (cp)); + formsw = mh_xstrdup(etcpath(cp)); continue; case HEADSW: @@ -308,7 +308,7 @@ do_cache: /* Check for private cache location */ if (!(cache_private = context_find (nmhprivcache))) cache_private = ".cache"; - cache_private = getcpy (m_maildir (cache_private)); + cache_private = mh_xstrdup(m_maildir(cache_private)); if (!context_find ("path")) free (path ("./", TFOLDER)); diff --git a/uip/mhshowsbr.c b/uip/mhshowsbr.c index b669ad53..5283179d 100644 --- a/uip/mhshowsbr.c +++ b/uip/mhshowsbr.c @@ -101,7 +101,7 @@ show_all_messages(CT *cts, int concat, int textonly, int inlineonly) * for showing headers of MIME messages. */ if (!formsw) - formsw = getcpy (etcpath ("mhl.headers")); + formsw = mh_xstrdup(etcpath("mhl.headers")); /* * Compile the content marker and header format lines diff --git a/uip/mhstore.c b/uip/mhstore.c index 7fa819aa..b7c9943b 100644 --- a/uip/mhstore.c +++ b/uip/mhstore.c @@ -239,7 +239,7 @@ do_cache: /* Check for private cache location */ if (!(cache_private = context_find (nmhprivcache))) cache_private = ".cache"; - cache_private = getcpy (m_maildir (cache_private)); + cache_private = mh_xstrdup(m_maildir(cache_private)); /* * Cache the current directory before we do any chdirs()'s. diff --git a/uip/refile.c b/uip/refile.c index be1294fe..3035f2c6 100644 --- a/uip/refile.c +++ b/uip/refile.c @@ -135,7 +135,7 @@ main (int argc, char **argv) if (filep > NFOLDERS) adios (NULL, "only %d files allowed!", NFOLDERS); isdf = 0; - files[filep++] = getcpy (m_draft (NULL, NULL, 1, &isdf)); + files[filep++] = mh_xstrdup(m_draft(NULL, NULL, 1, &isdf)); continue; case FILESW: if (filep > NFOLDERS) diff --git a/uip/repl.c b/uip/repl.c index f213eb30..79a4522c 100644 --- a/uip/repl.c +++ b/uip/repl.c @@ -253,7 +253,7 @@ main (int argc, char **argv) case FILTSW: if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); - filter = getcpy (etcpath (cp)); + filter = mh_xstrdup(etcpath(cp)); mime = 0; continue; case FORMSW: @@ -262,7 +262,7 @@ main (int argc, char **argv) continue; case FRMTSW: - filter = getcpy (etcpath (mhlreply)); + filter = mh_xstrdup(etcpath(mhlreply)); mime = 0; continue; case NFRMTSW: diff --git a/uip/send.c b/uip/send.c index 7f665ba4..0546bf56 100644 --- a/uip/send.c +++ b/uip/send.c @@ -133,7 +133,7 @@ main (int argc, char **argv) vec = argsplit(postproc, &program, &vecp); vec[vecp++] = "-library"; - vec[vecp++] = getcpy (m_maildir ("")); + vec[vecp++] = mh_xstrdup(m_maildir("")); if ((cp = context_find ("fileproc"))) { vec[vecp++] = "-fileproc"; @@ -317,7 +317,7 @@ main (int argc, char **argv) if (dfolder == NULL) { if (msgp == 0) { - msgs[msgp++] = getcpy (m_draft (NULL, NULL, 1, &isdf)); + msgs[msgp++] = mh_xstrdup(m_draft(NULL, NULL, 1, &isdf)); if (stat (msgs[0], &st) == NOTOK) adios (msgs[0], "unable to stat draft file"); cp = concat ("Use \"", msgs[0], "\"? ", NULL); @@ -339,7 +339,7 @@ main (int argc, char **argv) } } else { for (msgnum = 0; msgnum < msgp; msgnum++) - msgs[msgnum] = getcpy (m_maildir (msgs[msgnum])); + msgs[msgnum] = mh_xstrdup(m_maildir(msgs[msgnum])); } } else { if (!context_find ("path")) diff --git a/uip/show.c b/uip/show.c index def62759..130ccce8 100644 --- a/uip/show.c +++ b/uip/show.c @@ -145,7 +145,7 @@ usage: app_msgarg(&vec, --cp); if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); - app_msgarg(&vec, getcpy (etcpath(cp))); + app_msgarg(&vec, mh_xstrdup(etcpath(cp))); continue; case PROGSW: @@ -204,7 +204,7 @@ usage: if (msgs.size) adios (NULL, "only one file at a time!"); if (draftsw) - app_msgarg(&vec, getcpy (m_draft (folder, NULL, 1, &isdf))); + app_msgarg(&vec, mh_xstrdup(m_draft(folder, NULL, 1, &isdf))); else app_msgarg(&vec, file); headersw = 0; diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index 10291617..4cab2bab 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -204,7 +204,7 @@ WhatNow (int argc, char **argv) } if ((drft == NULL && (drft = getenv ("mhdraft")) == NULL) || *drft == 0) - drft = getcpy (m_draft (dfolder, dmsg, 1, &isdf)); + drft = mh_xstrdup(m_draft(dfolder, dmsg, 1, &isdf)); msgnam = (cp = getenv ("mhaltmsg")) && *cp ? mh_xstrdup(cp) : NULL; @@ -1029,7 +1029,7 @@ sendit (char *sp, char **arg, char *file, int pushed) vec = argsplit(postproc, &program, &vecp); vec[vecp++] = "-library"; - vec[vecp++] = getcpy (m_maildir ("")); + vec[vecp++] = mh_xstrdup(m_maildir("")); if ((cp = context_find ("fileproc"))) { vec[vecp++] = "-fileproc"; diff --git a/uip/whom.c b/uip/whom.c index 76f434e4..b5935de9 100644 --- a/uip/whom.c +++ b/uip/whom.c @@ -74,7 +74,7 @@ main (int argc, char **argv) vec[vecp++] = invo_name; vec[vecp++] = "-whom"; vec[vecp++] = "-library"; - vec[vecp++] = getcpy (m_maildir ("")); + vec[vecp++] = mh_xstrdup(m_maildir("")); if ((cp = context_find ("credentials"))) { /* post doesn't read context so need to pass credentials. */ @@ -165,7 +165,7 @@ main (int argc, char **argv) } if (msg == NULL) { - cp = getcpy (m_draft (dfolder, dmsg, 1, &isdf)); + cp = mh_xstrdup(m_draft(dfolder, dmsg, 1, &isdf)); msg = vec[vecp++] = cp; } -- 2.56.0