aritosteles aritosteles - 1 year ago 106
C++ Question

App crash after modifying a structure

I'm having trouble with a project that compiles ok but crashes on startup before even reaching InitInstance().
This happens after I added a string to a struct:

typedef struct
long nChannelIndex;
TCHAR szChannelName[32];
DWORD dwStartTime; // time_t
DWORD dwPlaytimeMs; // msecs
TCHAR szStepName[32];
TCHAR szFilename[MAX_PATH];
long nLenMs;
TCHAR szStepDescr[64];
DWORD dwSessionID;
TCHAR szLocationName[32];
long bInsertion;
BOOL nOrigin; // 0= local, 1= cuemaster,
TCHAR szList[32];

When I added the last member of the structure the problem began. If I reduce the array size to a smaller number (say 12) the app works ok.

I get a crash in chkstk.asm - around this code:

; Find next lower page and probe
sub eax, _PAGESIZE_ ; decrease by PAGESIZE
test dword ptr [eax],eax ; probe page.
jmp short cs10

I am compiling a 32 bits c++ application on windows 7 Ultimate 64 bits. Msvc 2010.

Any Ideas?
Thanks for your help!

Answer Source

The name of the module where the crash occurs chkstk.asm is a clue to what is happening. It's checking the stack allocation to make sure you haven't run out. It appears you have run out, by adding a large new element to your structure. It's very hard to run out of stack space with a single structure, so I assume you have an array of them. Local variables are what get allocated to the stack, so the problem is likely a local variable containing an array of these structures.

You can give your program more stack space with the /F compiler switch.

You could also use a vector instead of an array, which will allocate the space in the heap instead of on the stack.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download