From: Nick Terrell Date: Fri, 21 Jan 2022 06:41:47 +0000 (-0800) Subject: [dibio] Fix assertion triggered by no inputs X-Git-Tag: v1.5.4^2~253^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=246982e782849d8646b2d5df6648319935669228;p=thirdparty%2Fzstd.git [dibio] Fix assertion triggered by no inputs 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. --- diff --git a/programs/dibio.c b/programs/dibio.c index d19f95448..147d1e7bf 100644 --- a/programs/dibio.c +++ b/programs/dibio.c @@ -27,9 +27,9 @@ #include /* memset */ #include /* fprintf, fopen, ftello64 */ #include /* errno */ -#include #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];