X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/68036228524d8e62588ace46d71aeb05ff04ffa4..8eb8c7987bc1be0c180e72c416d0bd8f26291183:/uip/mhfixmsg.c diff --git a/uip/mhfixmsg.c b/uip/mhfixmsg.c index 56253803..66b2eaca 100644 --- a/uip/mhfixmsg.c +++ b/uip/mhfixmsg.c @@ -285,7 +285,7 @@ main (int argc, char **argv) { } } - if (! (cts = (CT *) calloc ((size_t) 2, sizeof *cts))) { + if (! (cts = (CT *) mh_xcalloc ((size_t) 2, sizeof *cts))) { adios (NULL, "out of memory"); } ctp = cts; @@ -320,7 +320,8 @@ main (int argc, char **argv) { done (1); seq_setprev (mp); /* set the previous-sequence */ - if (! (cts = (CT *) calloc ((size_t) (mp->numsel + 1), sizeof *cts))) { + if (! (cts = + (CT *) mh_xcalloc ((size_t) (mp->numsel + 1), sizeof *cts))) { adios (NULL, "out of memory"); } ctp = cts; @@ -484,9 +485,11 @@ fix_boundary (CT *ct, int *message_mods) { if ((fixed = m_mktemp2 (NULL, invo_name, NULL, &(*ct)->c_fp))) { if (replace_boundary (*ct, fixed, part_boundary) == OK) { char *filename = add ((*ct)->c_file, NULL); + CT fixed_ct; free_content (*ct); - if ((*ct = parse_mime (fixed))) { + if ((fixed_ct = parse_mime (fixed))) { + *ct = fixed_ct; (*ct)->c_unlink = 1; ++*message_mods; @@ -494,6 +497,9 @@ fix_boundary (CT *ct, int *message_mods) { report (NULL, NULL, filename, "fix multipart boundary"); } + } else { + advise (NULL, "unable to parse fixed part"); + status = NOTOK; } free (filename); } else { @@ -670,7 +676,9 @@ replace_boundary (CT ct, char *file, char *boundary) { case BODY: fputs ("\n", fpout); /* buf will have a terminating NULL, skip it. */ - fwrite (buf, 1, bufsz-1, fpout); + if ((int) fwrite (buf, 1, bufsz-1, fpout) < bufsz-1) { + advise (file, "fwrite"); + } continue; case FILEEOF: @@ -939,9 +947,8 @@ ensure_text_plain (CT *ct, CT parent, int *message_mods, int replacetextplain) { case CT_MESSAGE: if ((*ct)->c_subtype == MESSAGE_EXTERNAL) { - struct exbody *e; + struct exbody *e = (struct exbody *) (*ct)->c_ctparams; - e = (struct exbody *) (*ct)->c_ctparams; status = ensure_text_plain (&e->eb_content, *ct, message_mods, replacetextplain); } @@ -989,7 +996,7 @@ static CT divide_part (CT ct) { CT new_part; - if ((new_part = (CT) calloc (1, sizeof *new_part)) == NULL) + if ((new_part = (CT) mh_xcalloc (1, sizeof *new_part)) == NULL) adios (NULL, "out of memory"); /* Just copy over what is needed for decoding. c_vrsn and @@ -1123,8 +1130,10 @@ reformat_part (CT ct, char *file, char *type, char *subtype, int c_type) { /* Identifies 7bit or 8bit content based on charset. */ static int charset_encoding (CT ct) { - int encoding = - strcasecmp (content_charset (ct), "US-ASCII") ? CE_8BIT : CE_7BIT; + char *ct_charset = content_charset (ct); + int encoding = strcasecmp (ct_charset, "US-ASCII") ? CE_8BIT : CE_7BIT; + + free (ct_charset); return encoding; } @@ -1141,11 +1150,11 @@ build_multipart_alt (CT first_alt, CT new_part, int type, int subtype) { struct multipart *m; const struct str2init *ctinit; - if ((ct = (CT) calloc (1, sizeof *ct)) == NULL) + if ((ct = (CT) mh_xcalloc (1, sizeof *ct)) == NULL) adios (NULL, "out of memory"); /* Set up the multipart/alternative part. These fields of *ct were - initialized to 0 by calloc(): + initialized to 0 by mh_xcalloc(): c_fp, c_unlink, c_begin, c_end, c_vrsn, c_ctline, c_celine, c_id, c_descr, c_dispo, c_partno, @@ -1249,13 +1258,13 @@ build_multipart_alt (CT first_alt, CT new_part, int type, int subtype) { p->mp_next->mp_next = NULL; p->mp_next->mp_part = first_alt; - if ((m = (struct multipart *) calloc (1, sizeof (struct multipart))) == + if ((m = (struct multipart *) mh_xcalloc (1, sizeof (struct multipart))) == NULL) adios (NULL, "out of memory"); m->mp_start = concat (boundary, "\n", NULL); m->mp_stop = concat (boundary, "--\n", NULL); m->mp_parts = p; - ct->c_ctparams = (void *) m; + ct->c_ctparams = m; free (boundary); @@ -1475,9 +1484,8 @@ decode_text_parts (CT ct, int encoding, int *message_mods) { case CT_MESSAGE: if (ct->c_subtype == MESSAGE_EXTERNAL) { - struct exbody *e; + struct exbody *e = (struct exbody *) ct->c_ctparams; - e = (struct exbody *) ct->c_ctparams; status = decode_text_parts (e->eb_content, encoding, message_mods); } break; @@ -1646,16 +1654,16 @@ strip_crs (CT ct, int *message_mods) { } else if (last_char_was_cr) { if (*cp != '\n') { if (write (fd, "\r", 1) < 0) { - advise (tempfile, "write of CR failed"); + advise (tempfile, "CR write"); } } if (write (fd, cp, 1) < 0) { - advise (tempfile, "write failed"); + advise (tempfile, "write"); } last_char_was_cr = 0; } else { if (write (fd, cp, 1) < 0) { - advise (tempfile, "write failed"); + advise (tempfile, "write"); } last_char_was_cr = 0; } @@ -1694,6 +1702,8 @@ strip_crs (CT ct, int *message_mods) { } } + free (charset); + return status; } @@ -1708,14 +1718,18 @@ convert_charsets (CT ct, char *dest_charset, int *message_mods) { status = convert_charset (ct, dest_charset, message_mods); if (status == OK) { if (verbosw) { + char *ct_charset = content_charset (ct); + report (NULL, ct->c_partno, ct->c_file, - "convert %s to %s", - content_charset(ct), dest_charset); + "convert %s to %s", ct_charset, dest_charset); + free (ct_charset); } } else { + char *ct_charset = content_charset (ct); + report ("iconv", ct->c_partno, ct->c_file, - "failed to convert %s to %s", - content_charset(ct), dest_charset); + "failed to convert %s to %s", ct_charset, dest_charset); + free (ct_charset); } } break; @@ -1735,9 +1749,8 @@ convert_charsets (CT ct, char *dest_charset, int *message_mods) { case CT_MESSAGE: if (ct->c_subtype == MESSAGE_EXTERNAL) { - struct exbody *e; + struct exbody *e = (struct exbody *) ct->c_ctparams; - e = (struct exbody *) ct->c_ctparams; status = convert_charsets (e->eb_content, dest_charset, message_mods); }