]> diplodocus.org Git - nmh/commitdiff
Replace some strdup() with mh_xstrdup().
authorRalph Corderoy <ralph@inputplus.co.uk>
Sun, 16 Apr 2017 13:01:42 +0000 (14:01 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sun, 16 Apr 2017 13:01:42 +0000 (14:01 +0100)
(This is an old patch I had stashed.)
Some surrounding `if...adios()' are removed too, but most of the
strdup() calls weren't being checked for success, thus their
replacement.

sbr/icalparse.y
sbr/mf.c
uip/forw.c
uip/inc.c
uip/mhical.c
uip/replsbr.c

index 972ff983d87adea77ee24726d6c43bcf3fee33d3..c0866325decf15872cb64877be263bb0437d4f51 100644 (file)
@@ -149,7 +149,7 @@ add_contentline (contentline *node, const char *name) {
     contentline *new_node;
 
     NEW0(new_node);
     contentline *new_node;
 
     NEW0(new_node);
-    new_node->name  = strdup (name);
+    new_node->name  = mh_xstrdup (name);
     new_node->next = node->next;
     node->next = new_node;
 
     new_node->next = node->next;
     node->next = new_node;
 
index a604ce918b94b533a6c52d80ef9d499bf30e8b0a..3074683795ef2a538ee381bc6a6f103354a7fce7 100644 (file)
--- a/sbr/mf.c
+++ b/sbr/mf.c
@@ -534,7 +534,7 @@ domain (char *buffer)
 static int
 route (char *buffer)
 {
 static int
 route (char *buffer)
 {
-    path = strdup ("@");
+    path = mh_xstrdup ("@");
 
     for (;;) {
        switch (my_lex (buffer)) {
 
     for (;;) {
        switch (my_lex (buffer)) {
index 501f65134766511cfa9d47d6e408c9298034296a..c03c7b406269611a834aeccca705a2497cb090f0 100644 (file)
@@ -379,7 +379,7 @@ try_it_again:
 
        for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
            if (is_selected (mp, msgnum)) {
 
        for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++)
            if (is_selected (mp, msgnum)) {
-               fwdmsg = strdup(m_name(msgnum));
+               fwdmsg = mh_xstrdup(m_name(msgnum));
                break;
            }
 
                break;
            }
 
index 1973a6af959cf1eaa4828194bfa8e66e47f1a8ae..0f7c4a0df1163283f2f999f60c86c7ad9ae15707 100644 (file)
--- a/uip/inc.c
+++ b/uip/inc.c
@@ -524,9 +524,7 @@ main (int argc, char **argv)
            qsort (Maildir, num_maildir_entries, sizeof(*Maildir), maildir_srt);
        }
 
            qsort (Maildir, num_maildir_entries, sizeof(*Maildir), maildir_srt);
        }
 
-       if ((cp = strdup(newmail)) == NULL)
-           adios (NULL, "error allocating memory to copy newmail");
-
+       cp = mh_xstrdup(newmail);
        newmail = cp;
     }
 
        newmail = cp;
     }
 
@@ -539,9 +537,7 @@ main (int argc, char **argv)
     if (!folder)
        folder = getfolder (0);
     maildir = m_maildir (folder);
     if (!folder)
        folder = getfolder (0);
     maildir = m_maildir (folder);
-
-    if ((maildir_copy = strdup(maildir)) == NULL)
-        adios (maildir, "error allocating memory to copy maildir");
+    maildir_copy = mh_xstrdup(maildir);
 
     if (!folder_exists(maildir)) {
         /* If the folder doesn't exist, and we're given the -silent flag,
 
     if (!folder_exists(maildir)) {
         /* If the folder doesn't exist, and we're given the -silent flag,
index 573d7cf41c31a6059faee04efdbfbf814f69150c..27f7c9f1bbefb8fc4c235d719eeefe57fcae8e7f 100644 (file)
@@ -332,10 +332,10 @@ convert_to_reply (contentline *clines, act action) {
             (node = find_contentline (clines, "BEGIN", "VEVENT"))) {
             contentline *new_node = add_contentline (node, "ATTENDEE");
 
             (node = find_contentline (clines, "BEGIN", "VEVENT"))) {
             contentline *new_node = add_contentline (node, "ATTENDEE");
 
-            add_param_name (new_node, strdup ("PARTSTAT"));
-            add_param_value (new_node, strdup (partstat));
-            add_param_name (new_node, strdup ("CN"));
-            add_param_value (new_node, strdup (getfullname ()));
+            add_param_name (new_node, mh_xstrdup ("PARTSTAT"));
+            add_param_value (new_node, mh_xstrdup (partstat));
+            add_param_name (new_node, mh_xstrdup ("CN"));
+            add_param_value (new_node, mh_xstrdup (getfullname ()));
             new_node->value = concat ("MAILTO:", getlocalmbox (), NULL);
         }
     }
             new_node->value = concat ("MAILTO:", getlocalmbox (), NULL);
         }
     }
@@ -369,7 +369,7 @@ convert_to_cancellation (contentline *clines) {
     if ((node = find_contentline (clines, "STATUS", 0))  &&
         ! strcasecmp (node->value, "CONFIRMED")) {
         free (node->value);
     if ((node = find_contentline (clines, "STATUS", 0))  &&
         ! strcasecmp (node->value, "CONFIRMED")) {
         free (node->value);
-        node->value = strdup ("CANCELLED");
+        node->value = mh_xstrdup ("CANCELLED");
     }
 
     if ((node = find_contentline (clines, "SEQUENCE", 0))) {
     }
 
     if ((node = find_contentline (clines, "SEQUENCE", 0))) {
@@ -378,7 +378,7 @@ convert_to_cancellation (contentline *clines) {
 
         (void) snprintf (buf, sizeof buf, "%d", sequence + 1);
         free (node->value);
 
         (void) snprintf (buf, sizeof buf, "%d", sequence + 1);
         free (node->value);
-        node->value = strdup (buf);
+        node->value = mh_xstrdup (buf);
     }
 }
 
     }
 }
 
@@ -389,24 +389,24 @@ convert_common (contentline *clines, act action) {
 
     if ((node = find_contentline (clines, "METHOD", 0))) {
         free (node->value);
 
     if ((node = find_contentline (clines, "METHOD", 0))) {
         free (node->value);
-        node->value = strdup (action == ACT_CANCEL  ?  "CANCEL"  :  "REPLY");
+        node->value = mh_xstrdup (action == ACT_CANCEL  ?  "CANCEL"  :  "REPLY");
     }
 
     if ((node = find_contentline (clines, "PRODID", 0))) {
         free (node->value);
     }
 
     if ((node = find_contentline (clines, "PRODID", 0))) {
         free (node->value);
-        node->value = strdup ("nmh mhical v0.1");
+        node->value = mh_xstrdup ("nmh mhical v0.1");
     }
 
     if ((node = find_contentline (clines, "VERSION", 0))) {
         if (! node->value) {
             admonish (NULL, "Version property is missing value, assume 2.0");
     }
 
     if ((node = find_contentline (clines, "VERSION", 0))) {
         if (! node->value) {
             admonish (NULL, "Version property is missing value, assume 2.0");
-            node->value = strdup ("2.0");
+            node->value = mh_xstrdup ("2.0");
         }
 
         if (strcmp (node->value, "2.0")) {
             admonish (NULL, "supports the Version 2.0 specified by RFC 5545 "
                             "but iCalendar object has Version %s", node->value);
         }
 
         if (strcmp (node->value, "2.0")) {
             admonish (NULL, "supports the Version 2.0 specified by RFC 5545 "
                             "but iCalendar object has Version %s", node->value);
-            node->value = strdup ("2.0");
+            node->value = mh_xstrdup ("2.0");
         }
     }
 
         }
     }
 
@@ -458,7 +458,7 @@ convert_common (contentline *clines, act action) {
 
             if (strftime (buf, sizeof buf, "%Y%m%dT%H%M%SZ", &now_tm)) {
                 free (node->value);
 
             if (strftime (buf, sizeof buf, "%Y%m%dT%H%M%SZ", &now_tm)) {
                 free (node->value);
-                node->value = strdup (buf);
+                node->value = mh_xstrdup (buf);
             } else {
                 admonish (NULL, "strftime unable to format current time");
             }
             } else {
                 admonish (NULL, "strftime unable to format current time");
             }
@@ -523,7 +523,7 @@ output (FILE *file, contentline *clines, int contenttype) {
             char *line = NULL;
             size_t len;
 
             char *line = NULL;
             size_t len;
 
-            line = strdup (node->name);
+            line = mh_xstrdup (node->name);
             line = format_params (line, node->params);
 
             len = strlen (line);
             line = format_params (line, node->params);
 
             len = strlen (line);
@@ -576,20 +576,20 @@ display (FILE *file, contentline *clines, char *nfs) {
 
     if ((c = fmt_findcomp ("method"))) {
         if ((node = find_contentline (clines, "METHOD", 0))  &&  node->value) {
 
     if ((c = fmt_findcomp ("method"))) {
         if ((node = find_contentline (clines, "METHOD", 0))  &&  node->value) {
-            c->c_text = strdup (node->value);
+            c->c_text = mh_xstrdup (node->value);
         }
     }
 
     if ((c = fmt_findcomp ("organizer"))) {
         if ((node = find_contentline (clines, "ORGANIZER", 0))  &&
             node->value) {
         }
     }
 
     if ((c = fmt_findcomp ("organizer"))) {
         if ((node = find_contentline (clines, "ORGANIZER", 0))  &&
             node->value) {
-            c->c_text = strdup (identity (node));
+            c->c_text = mh_xstrdup (identity (node));
         }
     }
 
     if ((c = fmt_findcomp ("summary"))) {
         if ((node = find_contentline (clines, "SUMMARY", 0))  &&  node->value) {
         }
     }
 
     if ((c = fmt_findcomp ("summary"))) {
         if ((node = find_contentline (clines, "SUMMARY", 0))  &&  node->value) {
-            c->c_text = strdup (node->value);
+            c->c_text = mh_xstrdup (node->value);
         }
     }
 
         }
     }
 
@@ -601,7 +601,7 @@ display (FILE *file, contentline *clines, char *nfs) {
             if (node->name  &&  node->value  &&  ! in_valarm  &&
                 ! strcasecmp ("DESCRIPTION", node->name)  &&
                 strcasecmp (node->value, "\\n\\n")) {
             if (node->name  &&  node->value  &&  ! in_valarm  &&
                 ! strcasecmp ("DESCRIPTION", node->name)  &&
                 strcasecmp (node->value, "\\n\\n")) {
-                c->c_text = strdup (node->value);
+                c->c_text = mh_xstrdup (node->value);
             } else if (in_valarm) {
                 if (! strcasecmp ("END", node->name)  &&
                     ! strcasecmp ("VALARM", node->value)) {
             } else if (in_valarm) {
                 if (! strcasecmp ("END", node->name)  &&
                     ! strcasecmp ("VALARM", node->value)) {
@@ -619,7 +619,7 @@ display (FILE *file, contentline *clines, char *nfs) {
     if ((c = fmt_findcomp ("location"))) {
         if ((node = find_contentline (clines, "LOCATION", 0))  &&
             node->value) {
     if ((c = fmt_findcomp ("location"))) {
         if ((node = find_contentline (clines, "LOCATION", 0))  &&
             node->value) {
-            c->c_text = strdup (node->value);
+            c->c_text = mh_xstrdup (node->value);
         }
     }
 
         }
     }
 
@@ -642,7 +642,7 @@ display (FILE *file, contentline *clines, char *nfs) {
                 } else if (! strcasecmp ("DTSTART", node->name)) {
                     /* Got it:  DTSTART outside of a VTIMEZONE section. */
                     char *datetime = format_datetime (timezones, node);
                 } else if (! strcasecmp ("DTSTART", node->name)) {
                     /* Got it:  DTSTART outside of a VTIMEZONE section. */
                     char *datetime = format_datetime (timezones, node);
-                    c->c_text = datetime ? datetime : strdup(node->value);
+                    c->c_text = datetime ? datetime : mh_xstrdup(node->value);
                 }
             }
         }
                 }
             }
         }
index 15cab6c0e5e1f34af38b860ff98daf4d6f1f48b9..aff059a28c259767792c96e4668ef1300ceeb4a3 100644 (file)
@@ -525,7 +525,7 @@ fix_addresses (char *str) {
             struct mailname *mp;
 
             NEW(adr_nodep);
             struct mailname *mp;
 
             NEW(adr_nodep);
-            adr_nodep->adr = strdup (cp);
+            adr_nodep->adr = mh_xstrdup (cp);
             adr_nodep->escape_local_part = 0;
             adr_nodep->fixed = 0;
             adr_nodep->next = NULL;
             adr_nodep->escape_local_part = 0;
             adr_nodep->fixed = 0;
             adr_nodep->next = NULL;
@@ -552,12 +552,12 @@ fix_addresses (char *str) {
          * Walk the list and try to fix broken addresses.
          */
         for (np = adrs; np; np = np->next) {
          * Walk the list and try to fix broken addresses.
          */
         for (np = adrs; np; np = np->next) {
-            char *display_name = strdup (np->adr);
+            char *display_name = mh_xstrdup (np->adr);
             size_t len = strlen (display_name);
 
             if (np->escape_local_part) {
                 char *local_part_end = strrchr (display_name, '<');
             size_t len = strlen (display_name);
 
             if (np->escape_local_part) {
                 char *local_part_end = strrchr (display_name, '<');
-                char *angle_addr = strdup (local_part_end);
+                char *angle_addr = mh_xstrdup (local_part_end);
                 struct mailname *mp;
                 char *new_adr, *adr;
 
                 struct mailname *mp;
                 char *new_adr, *adr;
 
@@ -578,7 +578,7 @@ fix_addresses (char *str) {
                 free (angle_addr);
                 free (new_adr);
                 free (np->adr);
                 free (angle_addr);
                 free (new_adr);
                 free (np->adr);
-                np->adr = strdup (adr);
+                np->adr = mh_xstrdup (adr);
 
                 /* Need to flush getname() */
                 while ((cp = getname (""))) continue;
 
                 /* Need to flush getname() */
                 while ((cp = getname (""))) continue;
@@ -601,7 +601,7 @@ fix_addresses (char *str) {
                     free (fixed_str);
                     fixed_str = new_str;
                 } else {
                     free (fixed_str);
                     fixed_str = new_str;
                 } else {
-                    fixed_str = strdup (np->adr);
+                    fixed_str = mh_xstrdup (np->adr);
                 }
             }
 
                 }
             }
 
@@ -615,5 +615,5 @@ fix_addresses (char *str) {
         return fixed_str;
     }
     free (fixed_str);
         return fixed_str;
     }
     free (fixed_str);
-    return str  ?  strdup (str)  :  NULL;
+    return str  ?  mh_xstrdup (str)  :  NULL;
 }
 }