From: Fabian Keil Date: Wed, 17 Aug 2011 10:26:47 +0000 (+0000) Subject: In compress_buffer(), let zlib figure out the proper length for the new buffer X-Git-Tag: v_3_0_18~139 X-Git-Url: http://www.privoxy.org/gitweb/show-status?a=commitdiff_plain;h=43f55b819621d00730dc54b3ff121f4b5199c2cf;p=privoxy.git In compress_buffer(), let zlib figure out the proper length for the new buffer Simply adding 30 bytes is somewhat "suboptimal". --- diff --git a/cgi.c b/cgi.c index 0313a3e7..de80ead0 100644 --- a/cgi.c +++ b/cgi.c @@ -1,4 +1,4 @@ -const char cgi_rcs[] = "$Id: cgi.c,v 1.141 2011/07/17 13:34:36 fabiankeil Exp $"; +const char cgi_rcs[] = "$Id: cgi.c,v 1.142 2011/08/17 10:25:43 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/cgi.c,v $ @@ -1510,16 +1510,8 @@ char *compress_buffer(char *buffer, size_t *buffer_length, int compression_level uLongf new_length; assert(-1 <= compression_level && compression_level <= 9); - /* - * If the compression level is 0 or if the entropy - * is high, the "compressing" data will take more - * room then the uncompressed data due to the zlib - * overhead. - * - * XXX: The overhead isn't constant and 30 bytes - * may not be enough for everybody - */ - new_length = (uLongf)*buffer_length + 30; + /* Let zlib figure out the maximum length of the compressed data */ + new_length = compressBound((uLongf)*buffer_length); compressed_buffer = malloc(new_length); if (NULL == compressed_buffer)