Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestU01: Avoid overflow of internal static array. #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 71 additions & 6 deletions testu01/bbattery.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,47 @@
#define RABBIT_NUM 26
#define ALPHABIT_NUM 9

/* Count of p-values/statistics per battery in external arrays */
static const int SMALLCRUSH_RUNS[SMALLCRUSH_NUM] = {
1,1,1,1,1,2,1,1,1,5
};

static const int CRUSH_RUNS[CRUSH_NUM] = {
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,6,6,6,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
2,2,2,2,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,5,5,5,5,5,
2,2,1,1,1,2,2,1,1,1,
1,1,1,1,1,1,1,1,1,1,
2,2,1,1,1,1
};

static const int BIGCRUSH_RUNS[BIGCRUSH_NUM] = {
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,6,6,6,6,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,2,2,2,2,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,
1,1,1,5,5,5,5,5,5,2,
2,1,1,1,1,2,2,1,1,1,
1,1,1,1,1,1,1,1,1,1,
2,2,1,1,1,1
};

static const int RABBIT_RUNS[RABBIT_NUM] = {
1,1,1,1,2,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,2,
1,1,1,1,1,3*5
};

static const int ALPHABIT_RUNS[ALPHABIT_NUM] = {
1,1,1,1,1,1,1,5,5
};

double bbattery_pVal[1 + NDIM] = { 0 };
char *bbattery_TestNames[1 + NDIM] = { 0 };
Expand All @@ -79,6 +120,25 @@ static int TestNumber[1 + NDIM] = { 0 };
/*-------------------------------- Functions ------------------------------*/


static int CheckpValSize(const int num, const int runs[], int Rep[])
{
int i, j;

for (i = 1, j = 0 ; i <= num; i++) {
j += (Rep[i] * runs[i - 1]);
}

if (j > NDIM) {
printf ("ERROR Repetition count is too high and will overflow, aborting.\n");
return 0;
}
return 1;
}


/*=========================================================================*/


static void GetName (unif01_Gen * gen, char *genName)
{
char *p;
Expand Down Expand Up @@ -595,7 +655,8 @@ void bbattery_SmallCrushFile (char *filename)

void bbattery_RepeatSmallCrush (unif01_Gen * gen, int Rep[])
{
SmallCrush (gen, NULL, Rep);
if (CheckpValSize(SMALLCRUSH_NUM, SMALLCRUSH_RUNS, Rep))
SmallCrush (gen, NULL, Rep);
}


Expand Down Expand Up @@ -1601,7 +1662,8 @@ void bbattery_Crush (unif01_Gen * gen)

void bbattery_RepeatCrush (unif01_Gen * gen, int Rep[])
{
Crush (gen, Rep);
if (CheckpValSize(CRUSH_NUM, CRUSH_RUNS, Rep))
Crush (gen, Rep);
}


Expand Down Expand Up @@ -2694,7 +2756,8 @@ void bbattery_BigCrush (unif01_Gen * gen)

void bbattery_RepeatBigCrush (unif01_Gen * gen, int Rep[])
{
BigCrush (gen, Rep);
if (CheckpValSize(BIGCRUSH_NUM, BIGCRUSH_RUNS, Rep))
BigCrush (gen, Rep);
}


Expand Down Expand Up @@ -2985,7 +3048,8 @@ void bbattery_AlphabitFile (char *filename, double nb)
void bbattery_RepeatAlphabit (unif01_Gen * gen, double nb, int r, int s,
int Rep[])
{
Alphabit (gen, NULL, nb, r, s, FALSE, 0, Rep);
if (CheckpValSize(ALPHABIT_NUM, ALPHABIT_RUNS, Rep))
Alphabit (gen, NULL, nb, r, s, FALSE, 0, Rep);
}


Expand Down Expand Up @@ -3013,7 +3077,7 @@ void bbattery_BlockAlphabit (unif01_Gen * gen, double n, int r, int s)
void bbattery_RepeatBlockAlphabit (unif01_Gen * gen, double nb, int r, int s,
int Rep[], int L)
{
if ((L <= 32) && (L <= s)) {
if (CheckpValSize(ALPHABIT_NUM, ALPHABIT_RUNS, Rep) && (L <= 32) && (L <= s)) {
unif01_Gen *gen2;
gen2 = unif01_CreateBitBlockGen (gen, r, s, L);
Alphabit (gen2, NULL, nb, r, s, FALSE, 0, Rep);
Expand Down Expand Up @@ -3812,7 +3876,8 @@ void bbattery_RabbitFile (char *filename, double nb)

void bbattery_RepeatRabbit (unif01_Gen * gen, double nb, int Rep[])
{
Rabbit (gen, NULL, nb, Rep);
if (CheckpValSize(RABBIT_NUM, RABBIT_RUNS, Rep))
Rabbit (gen, NULL, nb, Rep);
}


Expand Down