]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
roundTripCrash automatic compression level now depends on first 128 bytes
authorYann Collet <yann.collet.73@gmail.com>
Mon, 20 Jun 2016 14:18:19 +0000 (16:18 +0200)
committerYann Collet <yann.collet.73@gmail.com>
Mon, 20 Jun 2016 14:18:19 +0000 (16:18 +0200)
programs/roundTripCrash.c

index 1b6e1d7b48202d1b08fd059d4e36f5e1bd935616..d5b673f44b159d4b8cae6034043acaaf30231d9b 100644 (file)
 #include <stdio.h>      /* fprintf */
 #include <sys/types.h>  /* stat */
 #include <sys/stat.h>   /* stat */
+#include "xxhash.h"
 #include "zstd.h"
 
+/*===========================================
+*   Macros
+*==========================================*/
+#define MIN(a,b)  ( (a) < (b) ? (a) : (b) )
+
 /** roundTripTest() :
 *   Compresses `srcBuff` into `compressedBuff`,
 *   then decompresses `compressedBuff` into `resultBuff`.
@@ -51,7 +57,9 @@ static size_t roundTripTest(void* resultBuff, size_t resultBuffCapacity,
                       const void* srcBuff, size_t srcBuffSize)
 {
     static const int maxClevel = 19;
-    int const cLevel = (!srcBuffSize) ? 1 : (*(const unsigned char*)srcBuff) % maxClevel;
+    size_t const hashLength = MIN(128, srcBuffSize);
+    unsigned const h32 = XXH32(srcBuff, hashLength, 0);
+    int const cLevel = h32 % maxClevel;
     size_t const cSize = ZSTD_compress(compressedBuff, compressedBuffCapacity, srcBuff, srcBuffSize, cLevel);
     if (ZSTD_isError(cSize)) {
         fprintf(stderr, "Compression error : %s \n", ZSTD_getErrorName(cSize));