Skip to content

Commit 928dfe7

Browse files
committed
Rework defensive check
1 parent 38f0b2c commit 928dfe7

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/Global.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,13 @@ void Global::computeHistogram(byte block[], int length, uint freqs[], bool isOrd
195195

196196
}
197197

198-
void Global::computeJobsPerTask(int jobsPerTask[], int jobs, int tasks)
198+
void Global::computeJobsPerTask(int jobsPerTask[], int jobs, int tasks) THROW
199199
{
200-
if ((jobs <= 0) || (tasks <= 0))
201-
return;
200+
if (jobs <= 0)
201+
throw invalid_argument("Invalid number of jobs provided");
202+
203+
if (tasks <= 0)
204+
throw invalid_argument("Invalid number of tasks provided");
202205

203206
int q = (jobs <= tasks) ? 1 : jobs / tasks;
204207
int r = (jobs <= tasks) ? 0 : jobs - q * tasks;

src/Global.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace kanzi {
4747

4848
static int log2_1024(uint32 x) THROW; // slow, accurate to 1/1024th
4949

50-
static void computeJobsPerTask(int jobsPerTask[], int jobs, int tasks);
50+
static void computeJobsPerTask(int jobsPerTask[], int jobs, int tasks) THROW;
5151

5252
static void computeHistogram(byte block[], int end, uint freqs[], bool isOrder0, bool withTotal=false);
5353

0 commit comments

Comments
 (0)