Use compressBound function to reserve the right amount of space.

compressBound function give the upper bound of space needed to
reserve to the compression buffer. Use it instead of using a define.
This commit is contained in:
Matthieu Gautier 2017-03-15 09:54:34 +01:00
parent e27ce444c6
commit 063e9ba80d

View File

@ -164,8 +164,9 @@ bool compress_content(string &content,
/* Compress the content if necessary */ /* Compress the content if necessary */
if (deflated) { if (deflated) {
pthread_mutex_lock(&compressorLock); pthread_mutex_lock(&compressorLock);
compr_buffer.reserve(COMPRESSOR_BUFFER_SIZE); uLong bufferBound = compressBound(contentLength);
uLongf comprLen = COMPRESSOR_BUFFER_SIZE; compr_buffer.reserve(bufferBound);
uLongf comprLen = compr_buffer.capacity();
int err = compress(&compr_buffer[0], &comprLen, (const Bytef*)(content.data()), contentLength); int err = compress(&compr_buffer[0], &comprLen, (const Bytef*)(content.data()), contentLength);
if (err == Z_OK && comprLen > 2 && comprLen < (contentLength+2)) { if (err == Z_OK && comprLen > 2 && comprLen < (contentLength+2)) {