From 246982e782849d8646b2d5df6648319935669228 Mon Sep 17 00:00:00 2001 From: Nick Terrell Date: Thu, 20 Jan 2022 22:41:47 -0800 Subject: [PATCH] [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. --- programs/dibio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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];