]> diplodocus.org Git - nmh/blobdiff - uip/mhfixmsg.c
uip/burst.c: Increase coverage.
[nmh] / uip / mhfixmsg.c
index eba84526f20644453fee95c986f17c36f66b39fe..086bac09ec811ca0aca16e674b2f7598948fd716 100644 (file)
@@ -676,7 +676,7 @@ fix_boundary (CT *ct, int *message_mods) {
  */
 static int
 get_multipart_boundary (CT ct, char **part_boundary) {
  */
 static int
 get_multipart_boundary (CT ct, char **part_boundary) {
-    char buffer[BUFSIZ];
+    char buffer[NMH_BUFSIZ];
     char *end_boundary = NULL;
     off_t begin = (off_t) ct->c_end > (off_t) (ct->c_begin + sizeof buffer)
         ?  (off_t) (ct->c_end - sizeof buffer)
     char *end_boundary = NULL;
     off_t begin = (off_t) ct->c_end > (off_t) (ct->c_begin + sizeof buffer)
         ?  (off_t) (ct->c_end - sizeof buffer)
@@ -684,7 +684,7 @@ get_multipart_boundary (CT ct, char **part_boundary) {
     size_t bytes_read;
     int status = OK;
 
     size_t bytes_read;
     int status = OK;
 
-    /* This will fail if the boundary spans fread() calls.  BUFSIZ should
+    /* This will fail if the boundary spans fread() calls.  NMH_BUFSIZ should
        be big enough, even if it's just 1024, to make that unlikely. */
 
     /* free_content() will close ct->c_fp. */
        be big enough, even if it's just 1024, to make that unlikely. */
 
     /* free_content() will close ct->c_fp. */
@@ -762,7 +762,7 @@ static int
 replace_boundary (CT ct, char *file, char *boundary) {
     FILE *fpin, *fpout;
     int compnum, state;
 replace_boundary (CT ct, char *file, char *boundary) {
     FILE *fpin, *fpout;
     int compnum, state;
-    char buf[BUFSIZ], name[NAMESZ];
+    char buf[NMH_BUFSIZ], name[NAMESZ];
     char *np, *vp;
     m_getfld_state_t gstate = 0;
     int status = OK;
     char *np, *vp;
     m_getfld_state_t gstate = 0;
     int status = OK;
@@ -819,9 +819,7 @@ replace_boundary (CT ct, char *file, char *boundary) {
                 fprintf (fpout, "%s:%s%s\n", np, new_ctline,
                         new_params ? new_params : "");
                free(new_ctline);
                 fprintf (fpout, "%s:%s%s\n", np, new_ctline,
                         new_params ? new_params : "");
                free(new_ctline);
-               if (new_params) {
-                   free(new_params);
-                }
+                mh_xfree(new_params);
             }
 
             free (vp);
             }
 
             free (vp);
@@ -830,7 +828,7 @@ replace_boundary (CT ct, char *file, char *boundary) {
             continue;
 
         case BODY:
             continue;
 
         case BODY:
-            fputs ("\n", fpout);
+            putc('\n', fpout);
             /* buf will have a terminating NULL, skip it. */
             if ((int) fwrite (buf, 1, bufsz-1, fpout) < bufsz-1) {
                 advise (file, "fwrite");
             /* buf will have a terminating NULL, skip it. */
             if ((int) fwrite (buf, 1, bufsz-1, fpout) < bufsz-1) {
                 advise (file, "fwrite");
@@ -924,10 +922,10 @@ fix_types (CT ct, svector_t fixtypes, int *message_mods) {
                            * c_ctline
                            */
                         /* Extract type and subtype from type/subtype. */
                            * c_ctline
                            */
                         /* Extract type and subtype from type/subtype. */
-                        ct_type = getcpy (ct_type_subtype);
+                        ct_type = mh_xstrdup(ct_type_subtype);
                         if ((cp = strchr (ct_type, '/'))) {
                             *cp = '\0';
                         if ((cp = strchr (ct_type, '/'))) {
                             *cp = '\0';
-                            ct_subtype = getcpy (++cp);
+                            ct_subtype = mh_xstrdup(++cp);
                         } else {
                             advise (NULL, "missing / in MIME type of %s %s",
                                     ct->c_file, ct->c_partno);
                         } else {
                             advise (NULL, "missing / in MIME type of %s %s",
                                     ct->c_file, ct->c_partno);
@@ -991,7 +989,7 @@ replace_substring (char **str, const char *old, const char *new) {
         char *prefix, *new_str;
 
         if (cp - *str) {
         char *prefix, *new_str;
 
         if (cp - *str) {
-            prefix = getcpy (*str);
+            prefix = mh_xstrdup(*str);
             *(prefix + (cp - *str)) = '\0';
             new_str = concat (prefix, new, remainder, NULL);
             free (prefix);
             *(prefix + (cp - *str)) = '\0';
             new_str = concat (prefix, new, remainder, NULL);
             free (prefix);
@@ -1002,9 +1000,9 @@ replace_substring (char **str, const char *old, const char *new) {
         free (*str);
 
         return *str = new_str;
         free (*str);
 
         return *str = new_str;
-    } else {
-        return NULL;
     }
     }
+
+    return NULL;
 }
 
 
 }
 
 
@@ -1180,9 +1178,9 @@ set_ce (CT ct, int encoding) {
         ct->c_celine = add (cte, NULL);
 
         return OK;
         ct->c_celine = add (cte, NULL);
 
         return OK;
-    } else {
-        return NOTOK;
     }
     }
+
+    return NOTOK;
 }
 
 
 }
 
 
@@ -1410,12 +1408,12 @@ insert_new_text_plain_part (CT ct, int new_subpart_number, CT parent) {
                     buffer, NULL);
 
         return 1;
                     buffer, NULL);
 
         return 1;
-    } else {
-        free_content (new_part->mp_part);
-        free (new_part);
-
-        return 0;
     }
     }
+
+    free_content (new_part->mp_part);
+    free (new_part);
+
+    return 0;
 }
 
 
 }
 
 
@@ -1540,10 +1538,10 @@ copy_ctinfo (CI dest, CI src) {
        d_pm = add_param(&dest->ci_first_pm, &dest->ci_last_pm, s_pm->pm_name,
                         s_pm->pm_value, 0);
        if (s_pm->pm_charset) {
        d_pm = add_param(&dest->ci_first_pm, &dest->ci_last_pm, s_pm->pm_name,
                         s_pm->pm_value, 0);
        if (s_pm->pm_charset) {
-           d_pm->pm_charset = getcpy(s_pm->pm_charset);
+           d_pm->pm_charset = mh_xstrdup(s_pm->pm_charset);
         }
        if (s_pm->pm_lang) {
         }
        if (s_pm->pm_lang) {
-           d_pm->pm_lang = getcpy(s_pm->pm_lang);
+           d_pm->pm_lang = mh_xstrdup(s_pm->pm_lang);
         }
     }
 
         }
     }
 
@@ -1601,14 +1599,13 @@ reformat_part (CT ct, char *file, char *type, char *subtype, int c_type) {
                     ct->c_file, invo_name, type, subtype);
         }
         return NOTOK;
                     ct->c_file, invo_name, type, subtype);
         }
         return NOTOK;
-    } else {
-        if (strchr (cf, '>')) {
-            advise (NULL, "'>' prohibited in \"%s\",\nplease fix your "
-                    "%s-format-%s/%s profile entry", cf, invo_name, type,
-                    subtype ? subtype : "");
+    }
+    if (strchr (cf, '>')) {
+        advise (NULL, "'>' prohibited in \"%s\",\nplease fix your "
+                "%s-format-%s/%s profile entry", cf, invo_name, type,
+                subtype ? subtype : "");
 
 
-            return NOTOK;
-        }
+        return NOTOK;
     }
 
     cp = concat (cf, " >", file, NULL);
     }
 
     cp = concat (cf, " >", file, NULL);
@@ -1632,7 +1629,8 @@ reformat_part (CT ct, char *file, char *type, char *subtype, int c_type) {
     }
 
     output_encoding = content_encoding (ct, &reason);
     }
 
     output_encoding = content_encoding (ct, &reason);
-    if (set_ct_type (ct, c_type, output_subtype, output_encoding) == OK) {
+    if (status == OK  &&
+        set_ct_type (ct, c_type, output_subtype, output_encoding) == OK) {
         ct->c_cefile.ce_file = file;
         ct->c_cefile.ce_unlink = 1;
     } else {
         ct->c_cefile.ce_file = file;
         ct->c_cefile.ce_unlink = 1;
     } else {
@@ -1782,7 +1780,7 @@ build_multipart_alt (CT first_alt, CT new_part, int type, int subtype) {
  */
 static int
 boundary_in_content (FILE **fp, char *file, const char *boundary) {
  */
 static int
 boundary_in_content (FILE **fp, char *file, const char *boundary) {
-    char buffer[BUFSIZ];
+    char buffer[NMH_BUFSIZ];
     size_t bytes_read;
     int found_boundary = 0;
 
     size_t bytes_read;
     int found_boundary = 0;
 
@@ -2076,7 +2074,7 @@ content_encoding (CT ct, const char **reason) {
 
     if (ce->ce_file) {
         size_t line_len = 0;
 
     if (ce->ce_file) {
         size_t line_len = 0;
-        char buffer[BUFSIZ];
+        char buffer[NMH_BUFSIZ];
         size_t inbytes;
 
         if (! ce->ce_fp  &&  (ce->ce_fp = fopen (ce->ce_file, "r")) == NULL) {
         size_t inbytes;
 
         if (! ce->ce_fp  &&  (ce->ce_fp = fopen (ce->ce_file, "r")) == NULL) {
@@ -2171,7 +2169,7 @@ strip_crs (CT ct, int *message_mods) {
         }
 
         if (fp  &&  *fp) {
         }
 
         if (fp  &&  *fp) {
-            char buffer[BUFSIZ];
+            char buffer[NMH_BUFSIZ];
             size_t bytes_read;
             size_t bytes_to_read =
                 end > 0 && end > begin  ?  end - begin  :  sizeof buffer;
             size_t bytes_read;
             size_t bytes_to_read =
                 end > 0 && end > begin  ?  end - begin  :  sizeof buffer;
@@ -2247,12 +2245,10 @@ strip_crs (CT ct, int *message_mods) {
                     status = NOTOK;
                 } else {
                     /* Replace the decoded file with the converted one. */
                     status = NOTOK;
                 } else {
                     /* Replace the decoded file with the converted one. */
-                    if (ct->c_cefile.ce_file) {
-                        if (ct->c_cefile.ce_unlink) {
-                            (void) m_unlink (ct->c_cefile.ce_file);
-                        }
-                        free (ct->c_cefile.ce_file);
-                    }
+                    if (ct->c_cefile.ce_file && ct->c_cefile.ce_unlink)
+                        (void) m_unlink (ct->c_cefile.ce_file);
+
+                    mh_xfree(ct->c_cefile.ce_file);
                     ct->c_cefile.ce_file = stripped_content_file;
                     ct->c_cefile.ce_unlink = 1;
 
                     ct->c_cefile.ce_file = stripped_content_file;
                     ct->c_cefile.ce_unlink = 1;
 
@@ -2527,12 +2523,9 @@ fix_always (CT ct, int *message_mods) {
  */
 static int
 fix_filename_param (char *name, char *value, PM *first_pm, PM *last_pm) {
  */
 static int
 fix_filename_param (char *name, char *value, PM *first_pm, PM *last_pm) {
-    size_t value_len;
     int fixed = 0;
 
     int fixed = 0;
 
-    if (((value_len = strlen (value)) > 0)  &&
-        strncmp (value, "=?", 2) == 0  &&
-        strncmp (&value[value_len - 2], "?=", 2) == 0) {
+    if (HasPrefix(value, "=?") && HasSuffix(value, "?=")) {
         /* Looks like an RFC 2047 encoded parameter. */
         char decoded[PATH_MAX + 1];
 
         /* Looks like an RFC 2047 encoded parameter. */
         char decoded[PATH_MAX + 1];
 
@@ -2603,8 +2596,8 @@ fix_filename_encoding (CT ct) {
                 const char *const new_params = concat (params, "\n", NULL);
 
                 replace_substring (&hf->value, semicolon_loc, new_params);
                 const char *const new_params = concat (params, "\n", NULL);
 
                 replace_substring (&hf->value, semicolon_loc, new_params);
-                free ((char *) new_params);
-                free ((char *) params);
+                free((void *)new_params); /* Cast away const.  Sigh. */
+                free((void *)params);
             } else {
                 advise (NULL, "did not find semicolon in %s:%s\n",
                         hf->name, hf->value);
             } else {
                 advise (NULL, "did not find semicolon in %s:%s\n",
                         hf->name, hf->value);
@@ -2642,7 +2635,7 @@ write_content (CT ct, const char *input_filename, char *outfile, int modify_inpl
                         int i = -1;
 
                         if (old != -1  &&  new != -1) {
                         int i = -1;
 
                         if (old != -1  &&  new != -1) {
-                            char buffer[BUFSIZ];
+                            char buffer[NMH_BUFSIZ];
 
                             while ((i = read (old, buffer, sizeof buffer)) >
                                    0) {
 
                             while ((i = read (old, buffer, sizeof buffer)) >
                                    0) {
@@ -2741,12 +2734,11 @@ remove_file (const char *file) {
 
         free (rmm_command);
         return WIFEXITED (status)  ?  WEXITSTATUS (status)  :  NOTOK;
 
         free (rmm_command);
         return WIFEXITED (status)  ?  WEXITSTATUS (status)  :  NOTOK;
-    } else {
-        /* This is OK for a non-message file, it still uses the
-           BACKUP_PREFIX form.  The backup file will be in the same
-           directory as file. */
-        return rename (file, m_backup (file));
     }
     }
+    /* This is OK for a non-message file, it still uses the
+       BACKUP_PREFIX form.  The backup file will be in the same
+       directory as file. */
+    return rename (file, m_backup (file));
 }
 
 
 }