summaryrefslogtreecommitdiffstats
path: root/lib/lz4.c
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2020-09-17 06:46:39 (GMT)
committerYann Collet <cyan@fb.com>2020-09-17 06:46:39 (GMT)
commitee01df1271518df8757e692ce10766e66472ea93 (patch)
tree30d8799f1646482344399eaa9a69a8f45a3f5e19 /lib/lz4.c
parentda1272979f4b79a7066631335a68512350a071fb (diff)
downloadlz4-ee01df1271518df8757e692ce10766e66472ea93.zip
lz4-ee01df1271518df8757e692ce10766e66472ea93.tar.gz
lz4-ee01df1271518df8757e692ce10766e66472ea93.tar.bz2
added the actual code change
Diffstat (limited to 'lib/lz4.c')
-rw-r--r--lib/lz4.c59
1 files changed, 53 insertions, 6 deletions
diff --git a/lib/lz4.c b/lib/lz4.c
index 0628eac..6d918ea 100644
--- a/lib/lz4.c
+++ b/lib/lz4.c
@@ -819,8 +819,13 @@ LZ4_prepareTable(LZ4_stream_t_internal* const cctx,
}
/** LZ4_compress_generic() :
- inlined, to ensure branches are decided at compilation time */
-LZ4_FORCE_INLINE int LZ4_compress_generic(
+ * inlined, to ensure branches are decided at compilation time.
+ * Presumed already validated at this stage:
+ * - source != NULL
+ * - inputSize > 0
+ * - outputDirective == notLimited || maxOutputSize > 0
+ */
+LZ4_FORCE_INLINE int LZ4_compress_generic_validated(
LZ4_stream_t_internal* const cctx,
const char* const source,
char* const dest,
@@ -867,11 +872,10 @@ LZ4_FORCE_INLINE int LZ4_compress_generic(
U32 offset = 0;
U32 forwardH;
- DEBUGLOG(5, "LZ4_compress_generic: srcSize=%i, tableType=%u", inputSize, tableType);
+ DEBUGLOG(5, "LZ4_compress_generic_validated: srcSize=%i, tableType=%u", inputSize, tableType);
+ assert(ip != NULL);
/* If init conditions are not met, we don't have to mark stream
* as having dirty context, since no action was taken yet */
- if (outputDirective == fillOutput && maxOutputSize < 1) { return 0; } /* Impossible to store anything */
- if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) { return 0; } /* Unsupported inputSize, too large (or negative) */
if ((tableType == byU16) && (inputSize>=LZ4_64Klimit)) { return 0; } /* Size too large (not within 64K limit) */
if (tableType==byPtr) assert(dictDirective==noDict); /* only supported use case with byPtr */
assert(acceleration >= 1);
@@ -1204,12 +1208,55 @@ _last_literals:
if (outputDirective == fillOutput) {
*inputConsumed = (int) (((const char*)ip)-source);
}
- DEBUGLOG(5, "LZ4_compress_generic: compressed %i bytes into %i bytes", inputSize, (int)(((char*)op) - dest));
result = (int)(((char*)op) - dest);
assert(result > 0);
+ DEBUGLOG(5, "LZ4_compress_generic: compressed %i bytes into %i bytes", inputSize, result);
return result;
}
+/** LZ4_compress_generic() :
+ * inlined, to ensure branches are decided at compilation time;
+ * takes care of input == (NULL, 0) and outputSize == 0
+ * and forward the rest to LZ4_compress_generic_validated */
+LZ4_FORCE_INLINE int LZ4_compress_generic(
+ LZ4_stream_t_internal* const cctx,
+ const char* const source,
+ char* const dest,
+ const int inputSize,
+ int *inputConsumed, /* only written when outputDirective == fillOutput */
+ const int maxOutputSize,
+ const limitedOutput_directive outputDirective,
+ const tableType_t tableType,
+ const dict_directive dictDirective,
+ const dictIssue_directive dictIssue,
+ const int acceleration)
+{
+ DEBUGLOG(5, "LZ4_compress_generic: srcSize=%i, maxOutputSize=%i",
+ inputSize, maxOutputSize);
+
+ /* If init conditions are not met, we don't have to mark stream
+ * as having dirty context, since no action was taken yet */
+ if (outputDirective != notLimited && maxOutputSize < 1) { return 0; } /* Impossible to store anything */
+ assert(dest != NULL);
+
+ if ((U32)inputSize > (U32)LZ4_MAX_INPUT_SIZE) { return 0; } /* Unsupported inputSize, too large (or negative) */
+ if (inputSize == 0) { /* source == NULL supported if inputSize == 0 */
+ assert(outputDirective == notLimited || maxOutputSize >= 1);
+ dest[0] = 0;
+ if (outputDirective == fillOutput) {
+ assert (inputConsumed != NULL);
+ *inputConsumed = 0;
+ }
+ return 1;
+ }
+ assert(source != NULL);
+
+ return LZ4_compress_generic_validated(cctx, source, dest, inputSize,
+ inputConsumed, /* only written when outputDirective == fillOutput */
+ maxOutputSize, outputDirective,
+ tableType, dictDirective, dictIssue, acceleration);
+}
+
int LZ4_compress_fast_extState(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int acceleration)
{