diff options
author | Yann Collet <cyan@fb.com> | 2022-01-31 07:01:50 (GMT) |
---|---|---|
committer | Yann Collet <cyan@fb.com> | 2022-01-31 07:02:55 (GMT) |
commit | 379c1a10cad71b004a4fa95a482c47ca0fa18835 (patch) | |
tree | 8631048d0ebce2e10665c1b0cd426eea8e2571ba /lib | |
parent | 756693083a0ac4c176101ca021809fe15d3a69ee (diff) | |
download | lz4-379c1a10cad71b004a4fa95a482c47ca0fa18835.zip lz4-379c1a10cad71b004a4fa95a482c47ca0fa18835.tar.gz lz4-379c1a10cad71b004a4fa95a482c47ca0fa18835.tar.bz2 |
Introduce MIN and MAX bounds to LZ4_MEMORY_USAGE
ensure that `frametest` works fine with these values,
notably with low LZ4_MEMORY_USAGE (dict test notably)
following suggestions from @t-mat at #1016
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lz4.c | 2 | ||||
-rw-r--r-- | lib/lz4.h | 16 | ||||
-rw-r--r-- | lib/lz4frame.c | 4 |
3 files changed, 16 insertions, 6 deletions
@@ -867,7 +867,7 @@ LZ4_FORCE_INLINE int LZ4_compress_generic_validated( const char* const source, char* const dest, const int inputSize, - int *inputConsumed, /* only written when outputDirective == fillOutput */ + int* inputConsumed, /* only written when outputDirective == fillOutput */ const int maxOutputSize, const limitedOutput_directive outputDirective, const tableType_t tableType, @@ -118,15 +118,25 @@ LZ4LIB_API const char* LZ4_versionString (void); /**< library version string; **************************************/ /*! * LZ4_MEMORY_USAGE : - * Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; etc.) - * Increasing memory usage improves compression ratio. - * Reduced memory usage may improve speed, thanks to better cache locality. + * Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; ) + * Increasing memory usage improves compression ratio, at the cost of speed. + * Reduced memory usage may improve speed at the cost of ratio, thanks to better cache locality. * Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache */ #ifndef LZ4_MEMORY_USAGE # define LZ4_MEMORY_USAGE 14 #endif +#define LZ4_MEMORY_USAGE_MIN 10 +#define LZ4_MEMORY_USAGE_MAX 20 + +#if (LZ4_MEMORY_USAGE < LZ4_MEMORY_USAGE_MIN) +# error "LZ4_MEMORY_USAGE is too small !" +#endif + +#if (LZ4_MEMORY_USAGE > LZ4_MEMORY_USAGE_MAX) +# error "LZ4_MEMORY_USAGE is too large !" +#endif /*-************************************ * Simple Functions diff --git a/lib/lz4frame.c b/lib/lz4frame.c index 73f21fc..f4ea02a 100644 --- a/lib/lz4frame.c +++ b/lib/lz4frame.c @@ -485,12 +485,12 @@ struct LZ4F_CDict_s { * When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once. * LZ4F_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay. * LZ4F_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only. - * `dictBuffer` can be released after LZ4F_CDict creation, since its content is copied within CDict + * @dictBuffer can be released after LZ4F_CDict creation, since its content is copied within CDict * @return : digested dictionary for compression, or NULL if failed */ LZ4F_CDict* LZ4F_createCDict(const void* dictBuffer, size_t dictSize) { const char* dictStart = (const char*)dictBuffer; - LZ4F_CDict* cdict = (LZ4F_CDict*) ALLOC(sizeof(*cdict)); + LZ4F_CDict* const cdict = (LZ4F_CDict*) ALLOC(sizeof(*cdict)); DEBUGLOG(4, "LZ4F_createCDict"); if (!cdict) return NULL; if (dictSize > 64 KB) { |