diff --git a/src/ChangeLog b/src/ChangeLog index 0755541d..f374605a 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2012-11-26 Giuseppe Scrivano + + * 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 * http.c (digest_authentication_encode): Add support for RFC 2617 diff --git a/src/warc.c b/src/warc.c index 3203d4de..fb506a7f 100644 --- a/src/warc.c +++ b/src/warc.c @@ -245,7 +245,7 @@ static bool 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); @@ -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 = "-"; - char offset_string[22]; + char offset_string[MAX_INT_TO_STRING_LEN(off_t)]; number_to_string (offset_string, offset); /* Print the CDX line. */ diff --git a/src/wget.h b/src/wget.h index ca4a702d..14a1965e 100644 --- a/src/wget.h +++ b/src/wget.h @@ -314,6 +314,10 @@ typedef double SUM_SIZE_INT; 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; /* Document type ("dt") flags */