Re: Stack Overflow on Insert

Jeff Nygren <[email protected]> Fri, 24 May 2002 12:50:45 -0500
Newsgroups gmane.comp.windows.devel.oledb.devel
Message-ID <[email protected]>
YES!!!

Kim, you just saved my butt.

Your hint led me to the "ATL and MFC String Conversion Macros" topic in
MSDN. There I noticed a comment about using the 'new' macros because "This
ensured that, UNLIKE THE OLDER TEXT CONVERSION MACROS, these classes are
safe to use in loops and WON'T OVERFLOW THE STACK".

I don't remember 'Uncle Bill' warning us about this 'feature' of the
string conversion macros before.

Thanks, much!

Jeff Nygren


...
    wcsncpy((WCHAR*)pszColumnBuf[iColumn + 1], (WCHAR*)T2OLE(strValue),
128); // kaboom!
    // ...
}

If you delve deeply enough into atlconv.h, you'll notice that T2OLE is
implemented using alloca, a CRT function for allocating memory on the
stack. It's fast as heck, but if you allocate too much memory you end up
with a stack overflow, obviously.

...
Hope that helps,
Kim

You can read messages from the OLEDB_DEV archive, unsubscribe from OLEDB_DEV,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.