You allocate about 14-15 GB of memory and for some reason the allocator cannot give it to you at the moment, so it callocreturns NULL, and you are segfault, because you are casting a NULL pointer.
Check if calloc returns NULL.
Suppose you are compiling a 64-bit program under 64-bit Linux. If you do something else - you can overflow the calculation to the first argument before calloc, if the long one is not 64 bits in your system.
For example, try
#include <stdlib.h>
#include <stdio.h>
#define N 44000L
int main(void)
{
size_t width = N * 2 - 1;
printf("Longs are %lu bytes. About to allocate %lu bytes\n",
sizeof(long), width * N * sizeof(int));
int *c = calloc(width * N, sizeof(int));
if (c == NULL) {
perror("calloc");
return 1;
}
c[N / 2] = 1;
return 0;
}
source
share