this is a unit module of a bigger program , which does permutations, the idea is to return a multidimensional array of the permutation results..but I'm getting a segmentation fault when allocation space to store the results..

can someone please tell me what I'm doing wrong?

Code:

int** permConstP(int *a, int arrStInd, int arrEndInd)
{
static int ** baseColours;
static int bcInd= 0;
//internal swap function
void swap(int *x, int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
if (arrStInd == arrEndInd)
{
baseColours[bcInd]=(int*)calloc(5, sizeof(int)); // getting a segmentation fault here in debugger
for(int i = 0; i <= arrEndInd ; i++)
{
//printf("%d ",a[i]);
baseColours[bcInd][i]=a[i];
}
bcInd++;
}
else
{
for (int i = arrStInd; i <= arrEndInd; i++)
{
swap((a+arrStInd), (a+i));
permConstP(a, arrStInd+1, arrEndInd,&baseColours, &bcInd); //backtrack
swap((a+arrStInd), (a+i));
}
}
return baseColours;
}