]> sjero.net Git - wget/commitdiff
warc: remove a magic number
authorGiuseppe Scrivano <gscrivano@gnu.org>
Mon, 26 Nov 2012 21:50:06 +0000 (22:50 +0100)
committerGiuseppe Scrivano <gscrivano@gnu.org>
Mon, 26 Nov 2012 21:50:06 +0000 (22:50 +0100)
src/ChangeLog
src/warc.c
src/wget.h

index 0755541df979a3d1cbcd2b05c0f7035562b75177..f374605abf6cb4192034b69b048293e8ae6525d9 100644 (file)
@@ -1,3 +1,10 @@
+2012-11-26  Giuseppe Scrivano  <gscrivano@gnu.org>
+
+       * wget.h (MAX_INT_TO_STRING_LEN): Define macro.
+       * warc.c (warc_write_block_from_file): Use `MAX_INT_TO_STRING_LEN'
+       to find the buffer size.
+       (warc_write_cdx_record): Likewise.
+
 2012-09-03  Tim Ruehsen  <tim.ruehsen@gmx.de>
 
        * http.c (digest_authentication_encode): Add support for RFC 2617
 2012-09-03  Tim Ruehsen  <tim.ruehsen@gmx.de>
 
        * http.c (digest_authentication_encode): Add support for RFC 2617
index 3203d4defe404b7eae7bfe61ea5895f6db4195dd..fb506a7f99aee4ad9405dd0aa0207df7130dd042 100644 (file)
@@ -245,7 +245,7 @@ static bool
 warc_write_block_from_file (FILE *data_in)
 {
   /* Add the Content-Length header. */
 warc_write_block_from_file (FILE *data_in)
 {
   /* Add the Content-Length header. */
-  char content_length[22];
+  char content_length[MAX_INT_TO_STRING_LEN(off_t)];
   fseeko (data_in, 0L, SEEK_END);
   number_to_string (content_length, ftello (data_in));
   warc_write_header ("Content-Length", content_length);
   fseeko (data_in, 0L, SEEK_END);
   number_to_string (content_length, ftello (data_in));
   warc_write_header ("Content-Length", content_length);
@@ -1225,7 +1225,7 @@ warc_write_cdx_record (const char *url, const char *timestamp_str,
   if (redirect_location == NULL || strlen(redirect_location) == 0)
     redirect_location = "-";
 
   if (redirect_location == NULL || strlen(redirect_location) == 0)
     redirect_location = "-";
 
-  char offset_string[22];
+  char offset_string[MAX_INT_TO_STRING_LEN(off_t)];
   number_to_string (offset_string, offset);
 
   /* Print the CDX line. */
   number_to_string (offset_string, offset);
 
   /* Print the CDX line. */
index ca4a702d11f56558be952ac0ed1ec72c407a6502..14a1965eb94ddfa27fd9a5bf9c9d660be116b138 100644 (file)
@@ -314,6 +314,10 @@ typedef double SUM_SIZE_INT;
    0-pad the address.)  */
 #define PTR_FORMAT(p) (int) (2 * sizeof (void *)), (unsigned long) (p)
 
    0-pad the address.)  */
 #define PTR_FORMAT(p) (int) (2 * sizeof (void *)), (unsigned long) (p)
 
+/* Find the maximum buffer length needed to print an integer of type `x'
+   in base 10. 24082 / 10000 = 8*log_{10}(2).  */
+#define MAX_INT_TO_STRING_LEN(x) ((sizeof(x) * 24082 / 10000) + 2)
+
 extern const char *exec_name;
 \f
 /* Document type ("dt") flags */
 extern const char *exec_name;
 \f
 /* Document type ("dt") flags */