4/28/09

msvc2005 release crash debug OK

I had a strange problem with Visual C++ 2005 today. I needed to add some feature to a program I developed several years ago. I used VC2005.

During debugging, everything's fine. But when I built a release and tested it, it crashed. So I set a breakpoint before the location where I thought it crashed, and run the debug, this is what I got:

How is that even possible? "0<0" is true?! Apparently the memory is messed up. I don't have time to get to the bottom of this so I just released the debug version.

(update 5/15/09: In case I forget. If I set Property->Configuration->C/C++->Code Generation->Basic Runtime Checks to "Stack Frames (/RTCs)", the program will works fine. From MS (http://msdn.microsoft.com/en-us/library/aa289171.aspx): /RTCs - Stack Frame Run-Time Error Checking
This option does several things that help to protect the stack from corruption.
* Initialize all local variables to non-zero values each time the function is called. This prevents inadvertent use of values on the stack from previous calls.
* Verify the stack pointer to check for corruption, such as that caused by defining a function as __stdcall in one place and __cdecl in another.
* Detect overruns and underruns of local variables. This differs from /GS because it is available only in debug builds, and it detects corruption on either end of a buffer and for all buffers.
)

No comments: