Hi everyone,
I've got a program that worked until recently. The offending code is shown here:
void writeTimeInfo(fitsfile *fptr, QList<QList<double> > &in)
{
double data[in.size() * in[0].size()];
long naxes[2];
int status = 0;
naxes[1] = in.size();
naxes[0] = in[0].size();
for (int i=0; i<naxes[1]; i++)
{
for (int j=0; j<naxes[0]; j++)
{
data[j+i*naxes[0]] = in[i][j];
}
}
fits_insert_img(fptr, DOUBLE_IMG, 2, naxes, &status);
fits_write_key(fptr, TSTRING, "EXTNAME", (void*)"HJD", "Extension name", &status);
fits_write_2d_dbl(fptr, 0, naxes[0], naxes[0], naxes[1], data, &status);
if (status)
fits_report_error(stderr, status);
}
The specifics of the program are not important (all the fits stuff, it is used to manipulate the astronomy standard fits files), but currently the program segfaults on the line
naxis[1] = in.size();
I cannot see what's wrong - before this step I can use gdb to see in.size() and in[0].size() *the two array dimensions) and I've checked the array values. It just segfaults here.
in
is a 2d QList array as you can see by the function argument list. The array is passed by reference so as to not duplicate memory. The only change I've made is running the program on a larger input set where before (the working stage): in was a 2d double array of 515*1508 elements, whereas now it is an array of 515*2480 elements. Could it be there is not enough memory on the stack?
Cheers