From: Brendan Cully Date: Thu, 29 Sep 2005 23:02:49 +0000 (+0000) Subject: Ensure that Content-Length printf format specifier matches off_t size, to X-Git-Tag: mutt-1-5-12-rel~324 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b6019c797135b0276a865ab335ea558b3b46fc78;p=mutt Ensure that Content-Length printf format specifier matches off_t size, to avoid mail-losing Content-Length: 0 (bug introduced by large file patch a couple of days ago). Closes: #2096. --- diff --git a/configure.in b/configure.in index bd516358..a32e29a9 100644 --- a/configure.in +++ b/configure.in @@ -42,6 +42,7 @@ AC_C_CONST AC_SYS_LARGEFILE AC_FUNC_FSEEKO +AC_CHECK_SIZEOF(off_t) AC_PATH_PROG(DBX, dbx, no) AC_PATH_PROG(GDB, gdb, no) @@ -86,10 +87,16 @@ AH_TEMPLATE([ICONV_NONTRANS], AH_BOTTOM([/* fseeko portability defines */ #ifdef HAVE_FSEEKO # define LOFF_T off_t +# if SIZEOF_OFF_T == 8 +# define OFF_T_FMT "%lld" +# else +# define OFF_T_FMT "%ld" +# endif #else # define LOFF_T long # define fseeko fseek # define ftello ftell +# define OFF_T_FMT "%ld" #endif ]) MUTT_C99_INTTYPES diff --git a/copy.c b/copy.c index c92d95ea..05a0e3bd 100644 --- a/copy.c +++ b/copy.c @@ -470,7 +470,7 @@ mutt_copy_header (FILE *in, HEADER *h, FILE *out, int flags, const char *prefix) if (flags & CH_UPDATE_LEN && (flags & CH_NOLEN) == 0) { - fprintf (out, "Content-Length: %ld\n", h->content->length); + fprintf (out, "Content-Length: " OFF_T_FMT "\n", h->content->length); if (h->lines != 0 || h->content->length == 0) fprintf (out, "Lines: %d\n", h->lines); } @@ -490,7 +490,7 @@ mutt_copy_header (FILE *in, HEADER *h, FILE *out, int flags, const char *prefix) } /* Count the number of lines and bytes to be deleted in this body*/ -static int count_delete_lines (FILE *fp, BODY *b, long *length, size_t datelen) +static int count_delete_lines (FILE *fp, BODY *b, LOFF_T *length, size_t datelen) { int dellines = 0; long l; @@ -498,7 +498,7 @@ static int count_delete_lines (FILE *fp, BODY *b, long *length, size_t datelen) if (b->deleted) { - fseek (fp, b->offset, SEEK_SET); + fseeko (fp, b->offset, SEEK_SET); for (l = b->length ; l ; l --) { ch = getc (fp); @@ -545,7 +545,7 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, { char prefix[SHORT_STRING]; STATE s; - long new_offset = -1; + LOFF_T new_offset = -1; int rc = 0; if (flags & M_CM_PREFIX) @@ -564,7 +564,7 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, else if (hdr->attach_del && (chflags & CH_UPDATE_LEN)) { int new_lines; - long new_length = body->length; + LOFF_T new_length = body->length; char date[SHORT_STRING]; mutt_make_date (date, sizeof (date)); @@ -579,7 +579,7 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, if (mutt_copy_header (fpin, hdr, fpout, chflags | CH_NOLEN | CH_NONEWLINE, NULL)) return -1; - fprintf (fpout, "Content-Length: %ld\n", new_length); + fprintf (fpout, "Content-Length: " OFF_T_FMT "\n", new_length); if (new_lines <= 0) new_lines = 0; else @@ -595,7 +595,7 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, #ifdef DEBUG { - long fail = ((ftell (fpout) - new_offset) - new_length); + LOFF_T fail = ((ftello (fpout) - new_offset) - new_length); if (fail) { @@ -633,7 +633,7 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, (chflags & CH_PREFIX) ? prefix : NULL) == -1) return -1; - new_offset = ftell (fpout); + new_offset = ftello (fpout); } if (flags & M_CM_DECODE) @@ -821,7 +821,7 @@ static int copy_delete_attach (BODY *b, FILE *fpin, FILE *fpout, char *date) { fprintf (fpout, "Content-Type: message/external-body; access-type=x-mutt-deleted;\n" - "\texpiration=%s; length=%ld\n" + "\texpiration=%s; length=" OFF_T_FMT "\n" "\n", date + 5, part->length); if (ferror (fpout)) return -1; diff --git a/sendlib.c b/sendlib.c index 95758d76..5f644772 100644 --- a/sendlib.c +++ b/sendlib.c @@ -2428,7 +2428,7 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, rewind (tempfp); while (fgets (sasha, sizeof (sasha), tempfp) != NULL) lines++; - fprintf (msg->fp, "Content-Length: %ld\n", (long) ftell (tempfp)); + fprintf (msg->fp, "Content-Length: " OFF_T_FMT "\n", (LOFF_T) ftell (tempfp)); fprintf (msg->fp, "Lines: %d\n\n", lines); /* copy the body and clean up */