heap overflow

Hi

I got the following error message:

Debug Assertion Failed!

Program: .exe
File:f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c
Line:584

Expression: (_HEAP_MAXREQ / nNum) >= nSize

Outside the main() function I have a function which I use for dynamic memory allocation of 2D array

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
double **zweidmatrix(int zeilen, int spalten)

   {
	int l;
	double **matrix;

   matrix = (double **)calloc(zeilen, sizeof(double *));
   if(NULL == matrix) printf("Kein Virtueller RAM mehr vorhanden ... !");

   for(l=0; l < zeilen; l++)

      {
      matrix[l] = (double *)calloc(spalten, sizeof(double));
      if(NULL == matrix[l]) printf("Kein Virtueller RAM mehr vorhanden ... !");
      }
	return matrix;
   }


In a debug mode break point is triggered for the line:
matrix[l] = (double *)calloc(spalten, sizeof(double));

Does anyone have an idea for the problem??

10x

The code look fine. Are you checking that zeilen or spalten are not getting any garbage values?

because if you give it a big value lets say 536870912:

_HEAP_MAXREQ / nNum >= nsize; //nsize = 8 for a double, nNum = 536870912

so the assertion will fail, this will give a value less than 8.

Last edited on
Hi,

actually spalten takes such garbage values... but I cannot figure out why....
Topic archived. No new replies allowed.