From 307128134089c807a9f86dfe6c3dc665982f329a Mon Sep 17 00:00:00 2001 From: "yann.collet.73@gmail.com" Date: Thu, 22 Sep 2011 13:11:17 +0000 Subject: [PATCH] Corrected issue 3 in compression function. Update is recommended. git-svn-id: https://lz4.googlecode.com/svn/trunk@26 650e7d94-2a16-8b24-b05c-7c0b3f6821cd --- lz4.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lz4.c b/lz4.c index fdf4fdd..ffc97b3 100644 --- a/lz4.c +++ b/lz4.c @@ -66,6 +66,7 @@ // Constants //************************************** #define MINMATCH 4 +#define MINLENGTH 6 #define SKIPSTRENGTH 6 #define STACKLIMIT 13 #define HEAPMODE (HASH_LOG>STACKLIMIT) // Defines if memory is allocated into the stack (local variable), or into the heap (malloc()). @@ -118,7 +119,8 @@ int LZ4_compressCtx(void** ctx, const BYTE* ip = (BYTE*) source; const BYTE* anchor = ip; const BYTE* const iend = ip + isize; - const BYTE* const ilimit = iend - MINMATCH; + const BYTE* const ilm = iend - 1; + const BYTE* const ilimit = iend - MINMATCH - 1; BYTE* op = (BYTE*) dest; BYTE* token; @@ -130,6 +132,7 @@ int LZ4_compressCtx(void** ctx, // Init + if (isize ilimit) { anchor = ip; break; } + if (ip > ilimit-1) { anchor = ip; break; } // Test next position ref = HashTable[HASH_VALUE(ip)]; @@ -221,14 +224,13 @@ _endCount: _last_literals: // Encode Last Literals - if (anchor < iend) { int lastLitRun = iend - anchor; if (lastLitRun>=(int)RUN_MASK) { *op++=(RUN_MASK< 254 ; lastLitRun-=255) *op++ = 255; *op++ = (BYTE) lastLitRun; } else *op++ = (lastLitRun<