From: Ralph Corderoy Date: Sun, 16 Apr 2017 13:01:42 +0000 (+0100) Subject: Replace some strdup() with mh_xstrdup(). X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/d6e8d44dbb990fe77f9380ef6cbcd5101807208e?hp=341ef606da3e17747949b67895300550db6aed9b Replace some strdup() with mh_xstrdup(). (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. --- diff --git a/sbr/icalparse.y b/sbr/icalparse.y index 972ff983..c0866325 100644 --- a/sbr/icalparse.y +++ b/sbr/icalparse.y @@ -149,7 +149,7 @@ add_contentline (contentline *node, const char *name) { 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; diff --git a/sbr/mf.c b/sbr/mf.c index a604ce91..30746837 100644 --- a/sbr/mf.c +++ b/sbr/mf.c @@ -534,7 +534,7 @@ domain (char *buffer) static int route (char *buffer) { - path = strdup ("@"); + path = mh_xstrdup ("@"); for (;;) { switch (my_lex (buffer)) { diff --git a/uip/forw.c b/uip/forw.c index 501f6513..c03c7b40 100644 --- a/uip/forw.c +++ b/uip/forw.c @@ -379,7 +379,7 @@ try_it_again: 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; } diff --git a/uip/inc.c b/uip/inc.c index 1973a6af..0f7c4a0d 100644 --- 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); } - if ((cp = strdup(newmail)) == NULL) - adios (NULL, "error allocating memory to copy newmail"); - + cp = mh_xstrdup(newmail); newmail = cp; } @@ -539,9 +537,7 @@ main (int argc, char **argv) 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, diff --git a/uip/mhical.c b/uip/mhical.c index 573d7cf4..27f7c9f1 100644 --- a/uip/mhical.c +++ b/uip/mhical.c @@ -332,10 +332,10 @@ convert_to_reply (contentline *clines, act action) { (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); } } @@ -369,7 +369,7 @@ convert_to_cancellation (contentline *clines) { 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))) { @@ -378,7 +378,7 @@ convert_to_cancellation (contentline *clines) { (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); - 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); - 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"); - 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); - 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); - node->value = strdup (buf); + node->value = mh_xstrdup (buf); } 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; - line = strdup (node->name); + line = mh_xstrdup (node->name); 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) { - 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) { - 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) { - 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")) { - 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)) { @@ -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) { - 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); - c->c_text = datetime ? datetime : strdup(node->value); + c->c_text = datetime ? datetime : mh_xstrdup(node->value); } } } diff --git a/uip/replsbr.c b/uip/replsbr.c index 15cab6c0..aff059a2 100644 --- a/uip/replsbr.c +++ b/uip/replsbr.c @@ -525,7 +525,7 @@ fix_addresses (char *str) { 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; @@ -552,12 +552,12 @@ fix_addresses (char *str) { * 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, '<'); - char *angle_addr = strdup (local_part_end); + char *angle_addr = mh_xstrdup (local_part_end); struct mailname *mp; char *new_adr, *adr; @@ -578,7 +578,7 @@ fix_addresses (char *str) { 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; @@ -601,7 +601,7 @@ fix_addresses (char *str) { 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 str ? strdup (str) : NULL; + return str ? mh_xstrdup (str) : NULL; }