]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[FSE] Add division by zero test
authorNick Terrell <terrelln@fb.com>
Mon, 30 Jul 2018 19:57:11 +0000 (12:57 -0700)
committerNick Terrell <terrelln@fb.com>
Mon, 30 Jul 2018 20:24:09 +0000 (13:24 -0700)
tests/fuzzer.c

index f7bacd5ca2b914342e92726fafcbb98cb9a957f5..8856a504a227542484de3afd3b56a4dd8c629d9b 100644 (file)
@@ -27,6 +27,7 @@
 #include <string.h>       /* strcmp */
 #include <assert.h>
 #define ZSTD_STATIC_LINKING_ONLY  /* ZSTD_compressContinue, ZSTD_compressBlock */
+#include "fse.h"
 #include "zstd.h"         /* ZSTD_VERSION_STRING */
 #include "zstd_errors.h"  /* ZSTD_getErrorCode */
 #include "zstdmt_compress.h"
@@ -1423,6 +1424,24 @@ static int basicUnitTests(U32 seed, double compressibility)
     }
     DISPLAYLEVEL(3, "OK \n");
 
+    DISPLAYLEVEL(3, "test%3i : testing FSE_normalizeCount() PR#1255: ", testNb++);
+    {
+        short norm[32];
+        unsigned count[32];
+        unsigned const tableLog = 5;
+        size_t const nbSeq = 32;
+        unsigned const maxSymbolValue = 31;
+        size_t i;
+
+        for (i = 0; i < 32; ++i)
+            count[i] = 1;
+        /* Calling FSE_normalizeCount() on a uniform distribution should not
+         * cause a division by zero.
+         */
+        FSE_normalizeCount(norm, tableLog, count, nbSeq, maxSymbolValue);
+    }
+    DISPLAYLEVEL(3, "OK \n");
+
 _end:
     free(CNBuffer);
     free(compressedBuffer);