]> diplodocus.org Git - nmh/blobdiff - uip/mhparse.c
Escape literal leading full stop in man/new.man.
[nmh] / uip / mhparse.c
index 0c2c17cd49b01e797c50ee3928192f76245ecc2f..a2dcb88c2e49503f78da26a6e4a72bce5fd02a8c 100644 (file)
@@ -34,13 +34,16 @@ int checksw = 0;    /* check Content-MD5 field */
  *    in a multipart.
  * 2) Suppress the warning about bogus multipart content, and report it.
  * 3) Suppress the warning about extraneous trailing ';' in header parameter
  *    in a multipart.
  * 2) Suppress the warning about bogus multipart content, and report it.
  * 3) Suppress the warning about extraneous trailing ';' in header parameter
- *    lists, and report it.
+ *    lists.
  */
 int skip_mp_cte_check;
 int suppress_bogus_mp_content_warning;
 int bogus_mp_content;
 int suppress_extraneous_trailing_semicolon_warning;
  */
 int skip_mp_cte_check;
 int suppress_bogus_mp_content_warning;
 int bogus_mp_content;
 int suppress_extraneous_trailing_semicolon_warning;
-int extraneous_trailing_semicolon;
+
+/*
+ * By default, suppress warning about multiple MIME-Version header fields.
+ */
 int suppress_multiple_mime_version_warning = 1;
 
 /* list of preferred type/subtype pairs, for -prefer */
 int suppress_multiple_mime_version_warning = 1;
 
 /* list of preferred type/subtype pairs, for -prefer */
@@ -206,6 +209,9 @@ parse_mime (char *file)
     FILE *fp;
     CT ct;
     size_t n;
     FILE *fp;
     CT ct;
     size_t n;
+    struct stat statbuf;
+
+    bogus_mp_content = 0;
 
     /*
      * Check if file is actually standard input
 
     /*
      * Check if file is actually standard input
@@ -217,7 +223,7 @@ parse_mime (char *file)
                   get_temp_dir());
             return NULL;
         }
                   get_temp_dir());
             return NULL;
         }
-       file = add (tfile, NULL);
+       file = mh_xstrdup(tfile);
 
        while ((n = fread(buffer, 1, sizeof(buffer), stdin)) > 0) {
            if (fwrite(buffer, 1, n, fp) != n) {
 
        while ((n = fread(buffer, 1, sizeof(buffer), stdin)) > 0) {
            if (fwrite(buffer, 1, n, fp) != n) {
@@ -239,6 +245,13 @@ parse_mime (char *file)
            return NULL;
        }
        fseek (fp, 0L, SEEK_SET);
            return NULL;
        }
        fseek (fp, 0L, SEEK_SET);
+    } else if (lstat (file, &statbuf) == NOTOK) {
+       advise (file, "unable to lstat");
+       return NULL;
+    } else if (S_ISDIR(statbuf.st_mode)) {
+       /* Don't try to parse a directory. */
+       advise (NULL, "%s is a directory", file);
+       return NULL;
     } else if ((fp = fopen (file, "r")) == NULL) {
        advise (file, "unable to read");
        return NULL;
     } else if ((fp = fopen (file, "r")) == NULL) {
        advise (file, "unable to read");
        return NULL;
@@ -312,8 +325,8 @@ get_content (FILE *in, char *file, int toplevel)
            compnum++;
 
            /* get copies of the buffers */
            compnum++;
 
            /* get copies of the buffers */
-           np = add (name, NULL);
-           vp = add (buf, NULL);
+           np = mh_xstrdup(name);
+           vp = mh_xstrdup(buf);
 
            /* if necessary, get rest of field */
            while (state == FLDPLUS) {
 
            /* if necessary, get rest of field */
            while (state == FLDPLUS) {
@@ -649,7 +662,7 @@ get_ctinfo (char *cp, CT ct, int magic)
     for (dp = cp; istoken (*dp); dp++)
        continue;
     c = *dp, *dp = '\0';
     for (dp = cp; istoken (*dp); dp++)
        continue;
     c = *dp, *dp = '\0';
-    ci->ci_type = add (cp, NULL);      /* store content type */
+    ci->ci_type = mh_xstrdup(cp);      /* store content type */
     *dp = c, cp = dp;
 
     if (!*ci->ci_type) {
     *dp = c, cp = dp;
 
     if (!*ci->ci_type) {
@@ -657,10 +670,7 @@ get_ctinfo (char *cp, CT ct, int magic)
                TYPE_FIELD, ct->c_file);
        return NOTOK;
     }
                TYPE_FIELD, ct->c_file);
        return NOTOK;
     }
-
-    /* down case the content type string */
-    for (dp = ci->ci_type; *dp; dp++)
-        *dp = tolower ((unsigned char) *dp);
+    to_lower(ci->ci_type);
 
     while (isspace ((unsigned char) *cp))
        cp++;
 
     while (isspace ((unsigned char) *cp))
        cp++;
@@ -671,7 +681,7 @@ get_ctinfo (char *cp, CT ct, int magic)
 
     if (*cp != '/') {
        if (!magic)
 
     if (*cp != '/') {
        if (!magic)
-           ci->ci_subtype = add ("", NULL);
+           ci->ci_subtype = mh_xstrdup("");
        goto magic_skip;
     }
 
        goto magic_skip;
     }
 
@@ -686,7 +696,7 @@ get_ctinfo (char *cp, CT ct, int magic)
     for (dp = cp; istoken (*dp); dp++)
        continue;
     c = *dp, *dp = '\0';
     for (dp = cp; istoken (*dp); dp++)
        continue;
     c = *dp, *dp = '\0';
-    ci->ci_subtype = add (cp, NULL);   /* store the content subtype */
+    ci->ci_subtype = mh_xstrdup(cp);   /* store the content subtype */
     *dp = c, cp = dp;
 
     if (!*ci->ci_subtype) {
     *dp = c, cp = dp;
 
     if (!*ci->ci_subtype) {
@@ -695,10 +705,7 @@ get_ctinfo (char *cp, CT ct, int magic)
                TYPE_FIELD, ct->c_file, ci->ci_type);
        return NOTOK;
     }
                TYPE_FIELD, ct->c_file, ci->ci_type);
        return NOTOK;
     }
-
-    /* down case the content subtype string */
-    for (dp = ci->ci_subtype; *dp; dp++)
-        *dp = tolower ((unsigned char) *dp);
+    to_lower(ci->ci_subtype);
 
 magic_skip:
     while (isspace ((unsigned char) *cp))
 
 magic_skip:
     while (isspace ((unsigned char) *cp))
@@ -718,10 +725,8 @@ magic_skip:
      * Get any <Content-Id> given in buffer
      */
     if (magic && *cp == '<') {
      * Get any <Content-Id> given in buffer
      */
     if (magic && *cp == '<') {
-       if (ct->c_id) {
-           free (ct->c_id);
-           ct->c_id = NULL;
-       }
+        mh_xfree(ct->c_id);
+        ct->c_id = NULL;
        if (!(dp = strchr(ct->c_id = ++cp, '>'))) {
            advise (NULL, "invalid ID in message %s", ct->c_file);
            return NOTOK;
        if (!(dp = strchr(ct->c_id = ++cp, '>'))) {
            advise (NULL, "invalid ID in message %s", ct->c_file);
            return NOTOK;
@@ -839,7 +844,7 @@ magic_skip:
      */
     if (*cp) {
         if (magic) {
      */
     if (*cp) {
         if (magic) {
-           ci->ci_magic = add (cp, NULL);
+           ci->ci_magic = mh_xstrdup(cp);
 
             /* If there is a Content-Disposition header and it doesn't
                have a *filename=, extract it from the magic contents.
 
             /* If there is a Content-Disposition header and it doesn't
                have a *filename=, extract it from the magic contents.
@@ -906,7 +911,7 @@ get_dispo (char *cp, CT ct, int buildflag)
     for (dp = cp; istoken (*dp); dp++)
        continue;
     c = *dp, *dp = '\0';
     for (dp = cp; istoken (*dp); dp++)
        continue;
     c = *dp, *dp = '\0';
-    ct->c_dispo_type = add (cp, NULL); /* store disposition type */
+    ct->c_dispo_type = mh_xstrdup(cp); /* store disposition type */
     *dp = c, cp = dp;
 
     if (*cp == '(' && get_comment (ct->c_file, DISPO_FIELD, &cp, NULL) == NOTOK)
     *dp = c, cp = dp;
 
     if (*cp == '(' && get_comment (ct->c_file, DISPO_FIELD, &cp, NULL) == NOTOK)
@@ -963,7 +968,7 @@ invalid:
 
        case '(':
            i++;
 
        case '(':
            i++;
-           /* and fall... */
+           /* FALLTHRU */
        default:
            *bp++ = c;
            continue;
        default:
            *bp++ = c;
            continue;
@@ -983,7 +988,7 @@ invalid:
            *commentp = concat (dp, " ", buffer, NULL);
            free (dp);
        } else {
            *commentp = concat (dp, " ", buffer, NULL);
            free (dp);
        } else {
-           *commentp = add (buffer, NULL);
+           *commentp = mh_xstrdup(buffer);
        }
     }
 
        }
     }
 
@@ -1095,7 +1100,7 @@ InitMultiPart (CT ct)
         ct->c_encoding != CE_8BIT  &&  ct->c_encoding != CE_BINARY) {
        /* Copy the Content-Transfer-Encoding header field body so we can
           remove any trailing whitespace and leading blanks from it. */
         ct->c_encoding != CE_8BIT  &&  ct->c_encoding != CE_BINARY) {
        /* Copy the Content-Transfer-Encoding header field body so we can
           remove any trailing whitespace and leading blanks from it. */
-       char *cte = add (ct->c_celine ? ct->c_celine : "(null)", NULL);
+       char *cte = mh_xstrdup(ct->c_celine ? ct->c_celine : "(null)");
 
        bp = cte + strlen (cte) - 1;
        while (bp >= cte && isspace ((unsigned char) *bp)) *bp-- = '\0';
 
        bp = cte + strlen (cte) - 1;
        while (bp >= cte && isspace ((unsigned char) *bp)) *bp-- = '\0';
@@ -1228,7 +1233,7 @@ end_part:
                continue;
            *next = NULL;
            free_content (p);
                continue;
            *next = NULL;
            free_content (p);
-           free ((char *) part);
+           free(part);
        }
     }
 
        }
     }
 
@@ -1260,7 +1265,7 @@ last_part:
            p = part->mp_part;
 
            sprintf (pp, "%d", partnum);
            p = part->mp_part;
 
            sprintf (pp, "%d", partnum);
-           p->c_partno = add (partnam, NULL);
+           p->c_partno = mh_xstrdup(partnam);
 
            /* initialize the content of the subparts */
            if (p->c_ctinitfnx && (*p->c_ctinitfnx) (p) == NOTOK) {
 
            /* initialize the content of the subparts */
            if (p->c_ctinitfnx && (*p->c_ctinitfnx) (p) == NOTOK) {
@@ -1534,7 +1539,7 @@ no_body:
                    case CT_MESSAGE:
                        if (p->c_subtype != MESSAGE_RFC822)
                            break;
                    case CT_MESSAGE:
                        if (p->c_subtype != MESSAGE_RFC822)
                            break;
-                       /* else fall... */
+                       /* FALLTHRU */
                    default:
                        e->eb_partno = ct->c_partno;
                        if (p->c_ctinitfnx)
                    default:
                        e->eb_partno = ct->c_partno;
                        if (p->c_ctinitfnx)
@@ -1767,7 +1772,7 @@ openBase64 (CT ct, char **file)
     if (*file == NULL) {
        ce->ce_unlink = 1;
     } else {
     if (*file == NULL) {
        ce->ce_unlink = 1;
     } else {
-       ce->ce_file = add (*file, NULL);
+       ce->ce_file = mh_xstrdup(*file);
        ce->ce_unlink = 0;
     }
 
        ce->ce_unlink = 0;
     }
 
@@ -1789,7 +1794,7 @@ openBase64 (CT ct, char **file)
            adios(NULL, "unable to create temporary file in %s",
                  get_temp_dir());
        }
            adios(NULL, "unable to create temporary file in %s",
                  get_temp_dir());
        }
-       ce->ce_file = add (tempfile, NULL);
+       ce->ce_file = mh_xstrdup(tempfile);
     }
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
     }
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
@@ -1840,7 +1845,7 @@ openBase64 (CT ct, char **file)
         for (i = 0; i < decoded_len; ++i) {
             putc (*decoded_p++, ce->ce_fp);
         }
         for (i = 0; i < decoded_len; ++i) {
             putc (*decoded_p++, ce->ce_fp);
         }
-        free ((char *) decoded);
+        free(decoded);
         if (ferror (ce->ce_fp)) {
             content_error (ce->ce_file, ct, "error writing to");
             goto clean_up;
         if (ferror (ce->ce_fp)) {
             content_error (ce->ce_file, ct, "error writing to");
             goto clean_up;
@@ -1951,7 +1956,7 @@ openQuoted (CT ct, char **file)
     if (*file == NULL) {
        ce->ce_unlink = 1;
     } else {
     if (*file == NULL) {
        ce->ce_unlink = 1;
     } else {
-       ce->ce_file = add (*file, NULL);
+       ce->ce_file = mh_xstrdup(*file);
        ce->ce_unlink = 0;
     }
 
        ce->ce_unlink = 0;
     }
 
@@ -1973,7 +1978,7 @@ openQuoted (CT ct, char **file)
            adios(NULL, "unable to create temporary file in %s",
                  get_temp_dir());
        }
            adios(NULL, "unable to create temporary file in %s",
                  get_temp_dir());
        }
-       ce->ce_file = add (tempfile, NULL);
+       ce->ce_file = mh_xstrdup(tempfile);
     }
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
     }
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
@@ -2171,7 +2176,7 @@ open7Bit (CT ct, char **file)
     if (*file == NULL) {
        ce->ce_unlink = 1;
     } else {
     if (*file == NULL) {
        ce->ce_unlink = 1;
     } else {
-       ce->ce_file = add (*file, NULL);
+       ce->ce_file = mh_xstrdup(*file);
        ce->ce_unlink = 0;
     }
 
        ce->ce_unlink = 0;
     }
 
@@ -2193,7 +2198,7 @@ open7Bit (CT ct, char **file)
            adios(NULL, "unable to create temporary file in %s",
                  get_temp_dir());
        }
            adios(NULL, "unable to create temporary file in %s",
                  get_temp_dir());
        }
-       ce->ce_file = add (tempfile, NULL);
+       ce->ce_file = mh_xstrdup(tempfile);
     }
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
     }
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
@@ -2536,16 +2541,16 @@ openFTP (CT ct, char **file)
     }
 
     if (*file)
     }
 
     if (*file)
-       ce->ce_file = add (*file, NULL);
+       ce->ce_file = mh_xstrdup(*file);
     else if (caching)
     else if (caching)
-       ce->ce_file = add (cachefile, NULL);
+       ce->ce_file = mh_xstrdup(cachefile);
     else {
        char *tempfile;
        if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
            adios(NULL, "unable to create temporary file in %s",
                  get_temp_dir());
        }
     else {
        char *tempfile;
        if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
            adios(NULL, "unable to create temporary file in %s",
                  get_temp_dir());
        }
-       ce->ce_file = add (tempfile, NULL);
+       ce->ce_file = mh_xstrdup(tempfile);
     }
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
     }
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
@@ -2734,10 +2739,10 @@ openMail (CT ct, char **file)
            adios(NULL, "unable to create temporary file in %s",
                  get_temp_dir());
        }
            adios(NULL, "unable to create temporary file in %s",
                  get_temp_dir());
        }
-       ce->ce_file = add (tempfile, NULL);
+       ce->ce_file = mh_xstrdup(tempfile);
        ce->ce_unlink = 1;
     } else {
        ce->ce_unlink = 1;
     } else {
-       ce->ce_file = add (*file, NULL);
+       ce->ce_file = mh_xstrdup(*file);
        ce->ce_unlink = 0;
     }
 
        ce->ce_unlink = 0;
     }
 
@@ -2748,9 +2753,8 @@ openMail (CT ct, char **file)
 
     /* showproc is for mhshow and mhstore, though mhlist -debug
      * prints it, too. */
 
     /* showproc is for mhshow and mhstore, though mhlist -debug
      * prints it, too. */
-    if (ct->c_showproc)
-       free (ct->c_showproc);
-    ct->c_showproc = add ("true", NULL);
+    mh_xfree(ct->c_showproc);
+    ct->c_showproc = mh_xstrdup("true");
 
     fseek (ce->ce_fp, 0L, SEEK_SET);
     *file = ce->ce_file;
 
     fseek (ce->ce_fp, 0L, SEEK_SET);
     *file = ce->ce_file;
@@ -2817,16 +2821,16 @@ openURL (CT ct, char **file)
     }
 
     if (*file)
     }
 
     if (*file)
-       ce->ce_file = add(*file, NULL);
+        ce->ce_file = mh_xstrdup(*file);
     else if (caching)
     else if (caching)
-       ce->ce_file = add(cachefile, NULL);
+        ce->ce_file = mh_xstrdup(cachefile);
     else {
        char *tempfile;
        if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
            adios(NULL, "unable to create temporary file in %s",
                  get_temp_dir());
        }
     else {
        char *tempfile;
        if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
            adios(NULL, "unable to create temporary file in %s",
                  get_temp_dir());
        }
-       ce->ce_file = add (tempfile, NULL);
+       ce->ce_file = mh_xstrdup(tempfile);
     }
 
     if ((ce->ce_fp = fopen(ce->ce_file, "w+")) == NULL) {
     }
 
     if ((ce->ce_fp = fopen(ce->ce_file, "w+")) == NULL) {
@@ -3291,7 +3295,6 @@ parse_header_attrs (const char *filename, const char *fieldname,
                        "parameter list",
                        filename, fieldname);
            }
                        "parameter list",
                        filename, fieldname);
            }
-           extraneous_trailing_semicolon = 1;
            return DONE;
        }
 
            return DONE;
        }
 
@@ -3406,8 +3409,7 @@ parse_header_attrs (const char *filename, const char *fieldname,
                           "field\n%*s(parameter %s)", filename, fieldname,
                           strlen(invo_name) + 2, "", nameptr);
                    free(nameptr);
                           "field\n%*s(parameter %s)", filename, fieldname,
                           strlen(invo_name) + 2, "", nameptr);
                    free(nameptr);
-                   if (charset)
-                       free(charset);
+                    mh_xfree(charset);
                    return NOTOK;
                }
 
                    return NOTOK;
                }
 
@@ -3432,10 +3434,8 @@ parse_header_attrs (const char *filename, const char *fieldname,
                               filename, fieldname, strlen(invo_name) + 2,
                               "", nameptr);
                        free(nameptr);
                               filename, fieldname, strlen(invo_name) + 2,
                               "", nameptr);
                        free(nameptr);
-                       if (charset)
-                           free(charset);
-                       if (lang)
-                           free(lang);
+                        mh_xfree(charset);
+                        mh_xfree(lang);
                        return NOTOK;
                    }
                    vp += 2;
                        return NOTOK;
                    }
                    vp += 2;
@@ -3478,10 +3478,8 @@ bad_quote:
                                filename, fieldname, strlen(invo_name) + 2, "",
                                nameptr);
                        free(nameptr);
                                filename, fieldname, strlen(invo_name) + 2, "",
                                nameptr);
                        free(nameptr);
-                       if (charset)
-                           free(charset);
-                       if (lang)
-                           free(lang);
+                        mh_xfree(charset);
+                        mh_xfree(lang);
                        return NOTOK;
                    case '"':
                        break;
                        return NOTOK;
                    case '"':
                        break;
@@ -3489,7 +3487,7 @@ bad_quote:
                    case '\\':
                        if (*++cp == '\0')
                            goto bad_quote;
                    case '\\':
                        if (*++cp == '\0')
                            goto bad_quote;
-                       /* FALL THROUGH */
+                       /* FALLTHRU */
                    default:
                        len++;
                        continue;
                    default:
                        len++;
                        continue;
@@ -3533,8 +3531,11 @@ bad_quote:
 
        if (partial) {
            for (pp = phead; pp != NULL; pp = pp->next) {
 
        if (partial) {
            for (pp = phead; pp != NULL; pp = pp->next) {
-               if (strcasecmp(nameptr, pp->name) == 0)
+               if (strcasecmp(nameptr, pp->name) == 0) {
+                    free (nameptr);
+                    nameptr = pp->name;
                    break;
                    break;
+                }
            }
 
            if (pp == NULL) {
            }
 
            if (pp == NULL) {
@@ -3563,7 +3564,6 @@ bad_quote:
                                "%s's %s: field\n%*s(parameter %s)", sp->index,
                                filename, fieldname, strlen(invo_name) + 2, "",
                                nameptr);
                                "%s's %s: field\n%*s(parameter %s)", sp->index,
                                filename, fieldname, strlen(invo_name) + 2, "",
                                nameptr);
-                       free (nameptr);
                        return NOTOK;
                    }
                    if (sp2->index < sp->index &&
                        return NOTOK;
                    }
                    if (sp2->index < sp->index &&
@@ -3579,7 +3579,6 @@ bad_quote:
                           "param in message %s's %s: field\n%*s(parameter %s)",
                           filename, fieldname, strlen(invo_name) + 2, "",
                           nameptr);
                           "param in message %s's %s: field\n%*s(parameter %s)",
                           filename, fieldname, strlen(invo_name) + 2, "",
                           nameptr);
-                   free (nameptr);
                    return NOTOK;
                }
            }
                    return NOTOK;
                }
            }
@@ -3589,11 +3588,9 @@ bad_quote:
             */
 
            if (index == 0 && encoded) {
             */
 
            if (index == 0 && encoded) {
-               if (pp->charset)
-                   free(pp->charset);
+                mh_xfree(pp->charset);
                pp->charset = charset;
                pp->charset = charset;
-               if (pp->lang)
-                   free(pp->lang);
+                mh_xfree(pp->lang);
                pp->lang = lang;
            }
        } else {
                pp->lang = lang;
            }
        } else {
@@ -3693,8 +3690,7 @@ output_params(size_t initialwidth, PM params, int *offsetout, int external)
 
        if (strlen(params->pm_name) > CPERLIN) {
            advise(NULL, "Parameter name \"%s\" is too long", params->pm_name);
 
        if (strlen(params->pm_name) > CPERLIN) {
            advise(NULL, "Parameter name \"%s\" is too long", params->pm_name);
-           if (paramout)
-               free(paramout);
+            mh_xfree(paramout);
            return NULL;
        }
 
            return NULL;
        }
 
@@ -3731,8 +3727,7 @@ output_params(size_t initialwidth, PM params, int *offsetout, int external)
                                 numchars, valoff);
 
            if (i == 0) {
                                 numchars, valoff);
 
            if (i == 0) {
-               if (paramout)
-                   free(paramout);
+                mh_xfree(paramout);
                return NULL;
            }
 
                return NULL;
            }
 
@@ -3795,8 +3790,7 @@ output_params(size_t initialwidth, PM params, int *offsetout, int external)
                             strlen(params->pm_value + valoff), valoff);
 
        if (i == 0) {
                             strlen(params->pm_value + valoff), valoff);
 
        if (i == 0) {
-           if (paramout)
-               free(paramout);
+            mh_xfree(paramout);
            return NULL;
        }
 
            return NULL;
        }
 
@@ -3945,7 +3939,7 @@ param_len(PM pm, int index, size_t valueoff, int *encode, int *cont,
            case '\\':
                len++;
                maxfit--;
            case '\\':
                len++;
                maxfit--;
-           /* FALL THROUGH */
+           /* FALLTHRU */
            default:
                len++;
                maxfit--;
            default:
                len++;
                maxfit--;
@@ -4053,6 +4047,7 @@ normal_param(PM pm, char *output, size_t len, size_t valuelen,
        case '"':
            *output++ = '\\';
            outlen++;
        case '"':
            *output++ = '\\';
            outlen++;
+           /* FALLTHRU */
        default:
            *output++ = *p++;
            outlen++;
        default:
            *output++ = *p++;
            outlen++;
@@ -4242,17 +4237,13 @@ noiconv:
 #endif /* HAVE_ICONV */
 
     /*
 #endif /* HAVE_ICONV */
 
     /*
-     * Take everything non-ASCII and substituite the replacement character
+     * Take everything non-ASCII and substitute the replacement character
      */
 
     q = buffer;
     bufsize = sizeof(buffer);
     for (p = pm->pm_value; *p != '\0' && bufsize > 1; p++, q++, bufsize--) {
      */
 
     q = buffer;
     bufsize = sizeof(buffer);
     for (p = pm->pm_value; *p != '\0' && bufsize > 1; p++, q++, bufsize--) {
-        /* FIXME: !iscntrl should perhaps be isprint as that allows all
-         * classes bar cntrl, whereas the cntrl class can include those
-         * in space and blank.
-         * http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap07.html */
-       if (isascii((unsigned char) *p) && !iscntrl((unsigned char) *p))
+       if (isascii((unsigned char) *p) && isprint((unsigned char) *p))
            *q = *p;
        else
            *q = replace;
            *q = *p;
        else
            *q = replace;