Skip to content

Commit

Permalink
bug fix: stack overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ppenna committed Feb 16, 2017
1 parent 60ec8be commit edb4527
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,12 @@ static void benchmark_dump(const double *respvar, int nthreads, const char *pref
static void benchmark_cpu(const unsigned *tasks, unsigned ntasks, int nthreads, long load)
{
long sum;
unsigned _tasks[ntasks];
unsigned *_tasks;
double loads[nthreads];
double times[nthreads];

_tasks = smalloc(ntasks*sizeof(unsigned));

memset(times, 0, nthreads*sizeof(double));
memset(loads, 0, nthreads*sizeof(unsigned));

Expand Down Expand Up @@ -178,6 +180,9 @@ static void benchmark_cpu(const unsigned *tasks, unsigned ntasks, int nthreads,

benchmark_dump(loads, nthreads, "cpu_load");
benchmark_dump(times, nthreads, "cpu_time");

/* House keeping. */
free(_tasks);
}

/**
Expand All @@ -191,11 +196,12 @@ static void benchmark_cpu(const unsigned *tasks, unsigned ntasks, int nthreads,
static void benchmark_cache(const unsigned *tasks, unsigned ntasks, int nthreads, long load)
{
long *array;
unsigned _tasks[ntasks];
unsigned *_tasks;
double loads[nthreads];
double times[nthreads];

array = smalloc(ntasks*sizeof(long));
_tasks = smalloc(ntasks*sizeof(unsigned));

memset(times, 0, nthreads*sizeof(double));
memset(loads, 0, nthreads*sizeof(unsigned));
Expand Down Expand Up @@ -236,6 +242,7 @@ static void benchmark_cache(const unsigned *tasks, unsigned ntasks, int nthreads
benchmark_dump(times, nthreads, "cache_time");

/* House keeping. */
free(_tasks);
free(array);
}

Expand All @@ -251,6 +258,7 @@ void benchmark(const unsigned *tasks, unsigned ntasks, int nthreads, long load)
{
/* Sanity check. */
assert(tasks != NULL);
assert(ntasks > 0);
assert(nthreads > 0);
assert(load > 0);

Expand Down

0 comments on commit edb4527

Please sign in to comment.