Home | History | Annotate | Download | only in linux
      1 
      2 /* Demonstrate Memcheck correctly handling chain of 64 recursive
      3    calls, each of which allocates a 1 M array on the stack.  Requires
      4    --main-stacksize=67117057 (on amd64-linux) or above, but works fine
      5    if you specify that. */
      6 
      7 #include <stdio.h>
      8 
      9 #define N_MBYTES 64
     10 
     11 #define N_INTS_PER_MBYTE (1048576 / sizeof(int))
     12 
     13 int rec ( int depth )
     14 {
     15    int i, zzz;
     16    int arr[N_INTS_PER_MBYTE];
     17    if (depth == 0) return 0;
     18    for (i = 0; i < N_INTS_PER_MBYTE; i++)
     19       arr[i] = i * depth;
     20    zzz = rec(depth-1);
     21    for (i = 0; i < N_INTS_PER_MBYTE; i++)
     22        zzz += arr[i];
     23    return zzz;
     24 }
     25 
     26 
     27 int main ( void )
     28 {
     29    int sum;
     30    fprintf(stderr, "lsframe2: start\n");
     31    sum = rec(N_MBYTES);
     32    fprintf(stderr, "lsframe2: done, result is %d\n", sum);
     33    return 0;
     34 }
     35