[VS2008 SP1][std::vector] _CRT_DEBUGGER_HOOK crash in Release mode only


After switching from VS2005 to VS2008(SP1) we ran into problems with legacy code - nothing new there. In most cases we detect some bugs and get rid of them. But this problem gives me quite a head ache as to were to continue looking.

The (MFC) application is based on a internal library. Both the library and the application were updated to work with VS2008. Now when we run the application in Debug mode 'everything' is fine. In Release mode however, we get into a crash to the desktop.

The crash originates from the std::vector iterator code and ends in

void __cdecl _CRT_DEBUGGER_HOOK(int _Reserved)
/* assign 0 to _debugger_hook_dummy so that the function is
not folded in retail */
_debugger_hook_dummy = 0;

The cause is an invalid parameter which somewhat verified when I turned

#define _SECURE_SCL 1

Because then we actually get an exception via

static void _Xran()
{ // report an out_of_range error
_THROW(out_of_range, "invalid vector<T> subscript");

Like I said, the problem only happens in Release mode under VS2008. If we compile both the internal library and the application with VS2005 than the application is fine in both Debug and Release mode.


Q: Right now, I am wondering if it is really a source code issue because it really only affects VS2008|Release and nothing else. Does anyone has an idea what could also cause these kind of issues?

I heard that it might be that some libraries got messed up in terms of what version of the CRT/MFC/ATL they link too.

Maybe we got a hidden inconsistency with a library regarding the compiler version it was created on?

Is there any tool to easily check each binary for the compiler version it was generated with?

Thanks for your time and any idea!


Source for reference:

+ HEADER +++++++++++++++++++++++
struct DATA_ITEM
CString text;

class CReport : public std::vector<DATA_ITEM>

BOOL New(INT iSubItems);

BOOL GetSubItem(INT iSubItem, [...]);
BOOL SetSubItem(INT iSubItem, [...]);

BOOL InsertSubItem(INT iSubItem, [...]);
BOOL DeleteSubItem(INT iSubItem);

Note: All methods are implemented but the crash seems to originate only from one of them
+ CODE +++++++++++++++++++++++++
BOOL CReportData::GetSubItem(INT iSubItem, [...])
INT iText;

if ((size_t)iSubItem >= size())
return FALSE;

const REPORT_DATA_ITEM& data = at (iSubItem); // <- Crashes Here

*pA = data.A;
*pB = data.B;
*pC = data.C;
*pD = data.D;
iText = data.E;

if(iText < 0)
*pLim = -1;

if(*pA == -1 && *pB == -1 && *pC == -1 && *pD == -1 && *pLim == -1)
return FALSE;

if(iText < 0)
return TRUE;

if (pText)
INT iSize;
for(iSize=0; iSize<(*pSize)-1 && iSize < iText; iSize++)
pText[iSize] = data.text[iSize];

pText[iSize] = 0;

return TRUE;

Relevant Pages