Click to See Complete Forum and Search --> : Not dropping core when referring out of bound address...


games_icon
June 23rd, 2008, 02:02 AM
Here's my prog running on solaris10.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct ThshldActionStat
{
char thshldAction[25];
};

const int MAX_THSHLDS_PER_GRP_CD = 50;
typedef ThshldActionStat ThshldGroupActions[MAX_THSHLDS_PER_GRP_CD];

int main()
{
ThshldGroupActions *thshldGroupActionStatsOver_;
ThshldGroupActions *thshldGroupActionStatsUnder_;

thshldGroupActionStatsOver_ = new ThshldGroupActions[55 + 1];
thshldGroupActionStatsUnder_ = new ThshldGroupActions[55 + 1];
int i,j;
for ( i=0;i<59;i++ )
for(j=0;j<67;j++)
{
strcpy( thshldGroupActionStatsOver_[i][j].thshldAction, "" );
strcpy( thshldGroupActionStatsUnder_[i][j].thshldAction, "" );
}
return 0;
}

It is running fine... which should drop core in general....
Can some one please help me here to say what's happening here?

Thx in advance!

souldog
June 23rd, 2008, 02:46 AM
the behavior in this case is undefined. It may or may not crash.. If you are lucky then it crashes

Paul McKenzie
June 23rd, 2008, 03:49 AM
It is running fine... which should drop core in general....Welcome to the world of 'C' programming, where writing beyond the boundaries of an array can do *anything*.

The program may work all the time, it may crash all the time, it may work sometimes and crash other times, it may work all the time on one machine, and crash all the time on another machine, etc...

As a matter of fact, there is nothing in the 'C' or C++ language definition that guarantees any code to crash -- in C++, you have exceptions, but that is still a language construct.

Regards,

Paul McKenzie