]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed : better error message when dictionary missing
authorYann Collet <cyan@fb.com>
Fri, 21 Dec 2018 01:20:07 +0000 (17:20 -0800)
committerYann Collet <cyan@fb.com>
Fri, 21 Dec 2018 01:20:07 +0000 (17:20 -0800)
during benchmark.
Also : refactored ZSTD_fillHashTable(),
just for readability (it does the same thing)

lib/compress/zstd_fast.c
programs/benchzstd.c
programs/fileio.c

index d54a5342f290a2880b7b3ee748076277dfccf91d..40ba0f73e65aa47447a318e9533c52532c6ba3d0 100644 (file)
@@ -27,18 +27,18 @@ void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
     /* Always insert every fastHashFillStep position into the hash table.
      * Insert the other positions if their hash entry is empty.
      */
-    for (; ip + fastHashFillStep - 1 <= iend; ip += fastHashFillStep) {
+    for ( ; ip + fastHashFillStep < iend + 2; ip += fastHashFillStep) {
         U32 const current = (U32)(ip - base);
-        U32 i;
-        for (i = 0; i < fastHashFillStep; ++i) {
-            size_t const hash = ZSTD_hashPtr(ip + i, hBits, mls);
-            if (i == 0 || hashTable[hash] == 0)
-                hashTable[hash] = current + i;
-            /* Only load extra positions for ZSTD_dtlm_full */
-            if (dtlm == ZSTD_dtlm_fast)
-                break;
-        }
-    }
+        size_t const hash0 = ZSTD_hashPtr(ip, hBits, mls);
+        hashTable[hash0] = current;
+        if (dtlm == ZSTD_dtlm_fast) continue;
+        /* Only load extra positions for ZSTD_dtlm_full */
+        {   U32 p;
+            for (p = 1; p < fastHashFillStep; ++p) {
+                size_t const hash = ZSTD_hashPtr(ip + p, hBits, mls);
+                if (hashTable[hash] == 0) {  /* not yet filled */
+                    hashTable[hash] = current + p;
+    }   }   }   }
 }
 
 FORCE_INLINE_TEMPLATE
index 30864f478b4295ff24cb7b838b03374195d40538..9076ec1da860d3cbf7f0b03bc116e6283626d0fa 100644 (file)
@@ -25,6 +25,7 @@
 #include <stdlib.h>      /* malloc, free */
 #include <string.h>      /* memset */
 #include <stdio.h>       /* fprintf, fopen */
+#include <errno.h>
 #include <assert.h>      /* assert */
 
 #include "benchfn.h"
@@ -799,6 +800,11 @@ BMK_benchOutcome_t BMK_benchFilesAdvanced(
     /* Load dictionary */
     if (dictFileName != NULL) {
         U64 const dictFileSize = UTIL_getFileSize(dictFileName);
+        if (dictFileSize == UTIL_FILESIZE_UNKNOWN) {
+            DISPLAYLEVEL(1, "error loading %s : %s \n", dictFileName, strerror(errno));
+            free(fileSizes);
+            RETURN_ERROR(9, BMK_benchOutcome_t, "benchmark aborted");
+        }
         if (dictFileSize > 64 MB) {
             free(fileSizes);
             RETURN_ERROR(10, BMK_benchOutcome_t, "dictionary file %s too large", dictFileName);
index d5cd341612b6a2da8e5cbb54af4fd52d5ca56284..ac4233e19621c74ed281d92ff6e346bac1744c60 100644 (file)
@@ -487,6 +487,7 @@ static size_t FIO_createDictBuffer(void** bufferPtr, const char* fileName)
     DISPLAYLEVEL(4,"Loading %s as dictionary \n", fileName);
     fileHandle = fopen(fileName, "rb");
     if (fileHandle==NULL) EXM_THROW(31, "%s: %s", fileName, strerror(errno));
+
     fileSize = UTIL_getFileSize(fileName);
     if (fileSize > DICTSIZE_MAX) {
         EXM_THROW(32, "Dictionary file %s is too large (> %u MB)",
@@ -495,7 +496,7 @@ static size_t FIO_createDictBuffer(void** bufferPtr, const char* fileName)
     *bufferPtr = malloc((size_t)fileSize);
     if (*bufferPtr==NULL) EXM_THROW(34, "%s", strerror(errno));
     {   size_t const readSize = fread(*bufferPtr, 1, (size_t)fileSize, fileHandle);
-        if (readSize!=fileSize)
+        if (readSize != fileSize)
             EXM_THROW(35, "Error reading dictionary file %s : %s",
                     fileName, strerror(errno));
     }