]> granicus.if.org Git - mutt/commitdiff
Ensure that Content-Length printf format specifier matches off_t size, to
authorBrendan Cully <brendan@kublai.com>
Thu, 29 Sep 2005 23:02:49 +0000 (23:02 +0000)
committerBrendan Cully <brendan@kublai.com>
Thu, 29 Sep 2005 23:02:49 +0000 (23:02 +0000)
avoid mail-losing Content-Length: 0 (bug introduced by large file patch a couple
of days ago). Closes: #2096.

configure.in
copy.c
sendlib.c

index bd516358bdee9a195d14666d4e143ab3261d6a1e..a32e29a9a1ece0833c5ae394997b71c120589f72 100644 (file)
@@ -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 c92d95ea1798d0fbb0f8ec2a4e588f7b11cf5522..05a0e3bdb090cd9493d5764293c02b3a073cbfbb 100644 (file)
--- 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;
index 95758d76d22e048b99ca76af9a1d3838250b1b2f..5f644772658177742e0bea7e29579d7af10a4fc1 100644 (file)
--- 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 */