]> diplodocus.org Git - nmh/commitdiff
Replace getcpy(f()) calls with mh_xstrdup() when f() can't be NULL.
authorRalph Corderoy <ralph@inputplus.co.uk>
Tue, 26 Sep 2017 13:32:08 +0000 (14:32 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Fri, 27 Oct 2017 15:38:22 +0000 (16:38 +0100)
And comment a few functions as never returning NULL along the way.

24 files changed:
config/config.c
sbr/arglist.c
sbr/context_read.c
sbr/getfolder.c
sbr/m_draft.c
sbr/m_maildir.c
sbr/r1bindex.c
uip/anno.c
uip/folder.c
uip/forw.c
uip/inc.c
uip/install-mh.c
uip/mhbuild.c
uip/mhlist.c
uip/mhn.c
uip/mhshow.c
uip/mhshowsbr.c
uip/mhstore.c
uip/refile.c
uip/repl.c
uip/send.c
uip/show.c
uip/whatnowsbr.c
uip/whom.c

index fa3df3b..2511472 100644 (file)
@@ -23,6 +23,7 @@
  * 3) Next, check in nmh Mail directory.
  * 4) Next, check in nmh `etc' directory.
  *
+ * Does not return NULL.
  */
 
 char *
index 9425439..026da19 100644 (file)
@@ -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)
index a8d1420..f899624 100644 (file)
@@ -26,6 +26,7 @@
 #include "m_maildir.h"
 #include "makedir.h"
 #include <pwd.h>                               /* 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);
index 15ee8a7..d1a298b 100644 (file)
@@ -8,6 +8,7 @@
 #include <h/mh.h>
 
 
+/* Does not return NULL. */
 char *
 getfolder(int wantcurrent)
 {
index a09bf06..ebf7ef7 100644 (file)
@@ -11,6 +11,7 @@
 #include "h/done.h"
 
 
+/* Does not return NULL. */
 char *
 m_draft (char *folder, char *msg, int use, int *isdf)
 {
index daf84a7..103d02c 100644 (file)
@@ -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);
index 7dcabb5..0fd8d51 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <h/mh.h>
 
+/* Does not return NULL. */
 char *
 r1bindex(char *str, int chr)
 {
index 77ecc10..1c4e0ca 100644 (file)
@@ -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);
 
index 001c342..3989a42 100644 (file)
@@ -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)));
        }
     }
 
index 288e85a..6ec53be 100644 (file)
@@ -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;
index e824ea3..552d793 100644 (file)
--- 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;
index 2470c3e..0d5b3bb 100644 (file)
@@ -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);
index b6f26eb..07074d7 100644 (file)
@@ -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));
index aa304e6..9e4b957 100644 (file)
@@ -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));
index 94f25ac..a5b4a27 100644 (file)
--- 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.
index d3b8504..13fa3b7 100644 (file)
@@ -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));
index b669ad5..5283179 100644 (file)
@@ -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
index 7fa819a..b7c9943 100644 (file)
@@ -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.
index be1294f..3035f2c 100644 (file)
@@ -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)
index f213eb3..79a4522 100644 (file)
@@ -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: 
index 7f665ba..0546bf5 100644 (file)
@@ -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"))
index def6275..130ccce 100644 (file)
@@ -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;
index 1029161..4cab2ba 100644 (file)
@@ -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";
index 76f434e..b5935de 100644 (file)
@@ -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;
     }