Changes LZ4F_compressBound() definition using NULL prefsPtr to cover worst case instead of default.

This commit is contained in:
Yann Collet 2015-04-14 18:51:36 +01:00
parent 348f5099e4
commit 05a46fc59a
3 changed files with 6 additions and 5 deletions

View File

@ -472,12 +472,13 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t compressionContext, void* ds
/* LZ4F_compressBound() : gives the size of Dst buffer given a srcSize to handle worst case situations. /* LZ4F_compressBound() : gives the size of Dst buffer given a srcSize to handle worst case situations.
* The LZ4F_frameInfo_t structure is optional : * The LZ4F_frameInfo_t structure is optional :
* you can provide NULL as argument, all preferences will then be set to default. * you can provide NULL as argument, preferences will then be set to cover worst case situations.
* */ * */
size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t* preferencesPtr) size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t* preferencesPtr)
{ {
LZ4F_preferences_t prefsNull; LZ4F_preferences_t prefsNull;
memset(&prefsNull, 0, sizeof(prefsNull)); memset(&prefsNull, 0, sizeof(prefsNull));
prefsNull.frameInfo.contentChecksumFlag = contentChecksumEnabled; /* worst case */
{ {
const LZ4F_preferences_t* prefsPtr = (preferencesPtr==NULL) ? &prefsNull : preferencesPtr; const LZ4F_preferences_t* prefsPtr = (preferencesPtr==NULL) ? &prefsNull : preferencesPtr;
blockSizeID_t bid = prefsPtr->frameInfo.blockSizeID; blockSizeID_t bid = prefsPtr->frameInfo.blockSizeID;

View File

@ -141,9 +141,9 @@ size_t LZ4F_compressBegin(LZ4F_compressionContext_t cctx, void* dstBuffer, size_
size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t* prefsPtr); size_t LZ4F_compressBound(size_t srcSize, const LZ4F_preferences_t* prefsPtr);
/* LZ4F_compressBound() : /* LZ4F_compressBound() :
* Provides the minimum size of Dst buffer given srcSize to handle worst case situations. * Provides the minimum size of Dst buffer given srcSize to handle worst case situations.
* prefsPtr is optional : you can provide NULL as argument, all preferences will then be set to default. * Different preferences can produce different results.
* Note that different preferences will produce different results. * prefsPtr is optional : you can provide NULL as argument, all preferences will then be set to cover worst case.
* This function doesn't include frame termination cost (4 bytes, or 8 is frame checksum is enabled) * This function includes frame termination cost (4 bytes, or 8 is frame checksum is enabled)
*/ */
size_t LZ4F_compressUpdate(LZ4F_compressionContext_t cctx, void* dstBuffer, size_t dstMaxSize, const void* srcBuffer, size_t srcSize, const LZ4F_compressOptions_t* cOptPtr); size_t LZ4F_compressUpdate(LZ4F_compressionContext_t cctx, void* dstBuffer, size_t dstMaxSize, const void* srcBuffer, size_t srcSize, const LZ4F_compressOptions_t* cOptPtr);

View File

@ -421,7 +421,7 @@ static cRess_t LZ4IO_createCResources(void)
/* Allocate Memory */ /* Allocate Memory */
ress.srcBuffer = malloc(blockSize); ress.srcBuffer = malloc(blockSize);
ress.srcBufferSize = blockSize; ress.srcBufferSize = blockSize;
ress.dstBufferSize = LZ4F_compressBound(blockSize, NULL); /* risk : real prefs may cost more */ ress.dstBufferSize = LZ4F_compressBound(blockSize, NULL); /* cover worst case */
ress.dstBuffer = malloc(ress.dstBufferSize); ress.dstBuffer = malloc(ress.dstBufferSize);
if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(31, "Allocation error : not enough memory"); if (!ress.srcBuffer || !ress.dstBuffer) EXM_THROW(31, "Allocation error : not enough memory");