]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Fixed asan issue reported by Maciej Adamczyk
authorYann Collet <yann.collet.73@gmail.com>
Tue, 3 Nov 2015 09:48:42 +0000 (10:48 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Tue, 3 Nov 2015 09:48:42 +0000 (10:48 +0100)
lib/zstd.c

index c7999445648ff5d630c033a23a0c5ddb1150aeb4..c7dcc262a386144bd8792952f4b0d12114440b09 100644 (file)
@@ -570,7 +570,7 @@ static size_t ZSTD_compressBlock(ZSTD_CCtx* ctx, void* dst, size_t maxDstSize, c
     ZSTD_resetSeqStore(seqStorePtr);
 
     /* Main Search Loop */
-    while (ip <= ilimit)
+    while (ip < ilimit)  /* < instead of <=, because unconditionnal ZSTD_addPtr(ip+1) */
     {
         const BYTE* match = ZSTD_updateMatch(HashTable, ip, base);
 
@@ -591,7 +591,8 @@ static size_t ZSTD_compressBlock(ZSTD_CCtx* ctx, void* dst, size_t maxDstSize, c
             ZSTD_addPtr(HashTable, ip+1, base);
             ip += matchLength + MINMATCH;
             anchor = ip;
-            if (ip <= ilimit) ZSTD_addPtr(HashTable, ip-2, base);
+            if (ip < ilimit) /* same test as loop, for speed */
+                ZSTD_addPtr(HashTable, ip-2, base);
         }
     }