]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[dibio] Fix assertion triggered by no inputs
authorNick Terrell <terrelln@fb.com>
Fri, 21 Jan 2022 06:41:47 +0000 (22:41 -0800)
committerNick Terrell <terrelln@fb.com>
Thu, 27 Jan 2022 21:56:59 +0000 (13:56 -0800)
Passing 0 inputs to `DiB_shuffle()` caused an assertion failure where
it should just return.

A test is added in a later commit, with the initial introduction of the
new testing framework.

Fixes #3007.

programs/dibio.c

index d19f954486f087bcd2494f106ad16ad74461df30..147d1e7bfdfd455de8a244eecb205bc34b19f4ac 100644 (file)
@@ -27,9 +27,9 @@
 #include <string.h>         /* memset */
 #include <stdio.h>          /* fprintf, fopen, ftello64 */
 #include <errno.h>          /* errno */
-#include <assert.h>
 
 #include "timefn.h"         /* UTIL_time_t, UTIL_clockSpanMicro, UTIL_getTime */
+#include "../lib/common/debug.h" /* assert */
 #include "../lib/common/mem.h"  /* read */
 #include "dibio.h"
 
@@ -193,7 +193,8 @@ static U32 DiB_rand(U32* src)
 static void DiB_shuffle(const char** fileNamesTable, unsigned nbFiles) {
     U32 seed = 0xFD2FB528;
     unsigned i;
-    assert(nbFiles >= 1);
+    if (nbFiles == 0)
+        return;
     for (i = nbFiles - 1; i > 0; --i) {
         unsigned const j = DiB_rand(&seed) % (i + 1);
         const char* const tmp = fileNamesTable[j];