Strange stack overflow?

I am facing a strange situation with passing a pointer to a structure with a very large array defined in the definition of struct {}, a float array of about 34 MB in size. In a nutshell, the psuedo code looks like this:

typedef config_t{
  ...
  float values[64000][64];
} CONFIG;


int32_t Create_Structures(CONFIG **the_config)
{
  CONFIG  *local_config;
  int32_t number_nodes;

  number_nodes = Find_Nodes();

  local_config = (CONFIG *)calloc(number_nodes,sizeof(CONFIG));
  *the_config = local_config;
  return(number_nodes);
}


int32_t Read_Config_File(CONFIG *the_config)
{
    /* do init work here */
    return(SUCCESS);
}


main()
{
    CONFIG *the_config;
    int32_t number_nodes,rc;

    number_nodes = Create_Structures(&the_config);

    rc = Read_Config_File(the_config);
    ...
    exit(0);
}

The code compiles fine, but when I try to run it, I get SIGSEGV in {under Read_Config_File ().

(gdb) run
...
Program received signal SIGSEGV, Segmentation fault.
0x0000000000407d0a in Read_Config_File (the_config=Cannot access memory at address 0x7ffffdf45428
) at ../src/config_parsing.c:763
763 {
(gdb) bt
#0  0x0000000000407d0a in Read_Config_File (the_config=Cannot access memory at address 0x7ffffdf45428
) at ../src/config_parsing.c:763
#1  0x00000000004068d2 in main (argc=1, argv=0x7fffffffe448) at ../src/main.c:148

I did this all the time with smaller arrays. And strange, 0x7fffffffe448 - 0x7ffffdf45428 = 0x20B8EF8, or about 34 MB of my float array.

Valgrind will give me a similar output:

==10894== Warning: client switching stacks?  SP change: 0x7ff000290 --> 0x7fcf47398
==10894==          to suppress, use: --max-stackframe=34311928 or greater
==10894== Invalid write of size 8
==10894==    at 0x407D0A: Read_Config_File (config_parsing.c:763)
==10894==    by 0x4068D1: main (main.c:148)
==10894==  Address 0x7fcf47398 is on thread 1 stack

All error messages indicate that I am compressing the stack pointer, but a) I have never encountered a failure when entering the function, and b) I pass the pointers around, not the actual array.

- ? 64- CentOS 2.6.18 gcc 4.1.2

!

Matt

+5
2

, config_t. gdb, 0x7fffffffe448 0x7ffffdf45428, .

$ gdb
GNU gdb 6.3.50-20050815 ...blahblahblah...
(gdb) p 0x7fffffffe448 - 0x7ffffdf45428  
$1 = 34312224

~ 34 , config_t. , , .

+1

, config_t, , . , : * CONFIG -.

+1

All Articles