Tutorial :Problem when disabling checked iterators in vs2008 SP1 (_HAS_ITERATOR_DEBUGGING=0)



Question:

I've been having some trouble with vs2008 SP1 running in debug mode when I try to disable checked iterators. The following program reproduces the problem (a crash in the string destructor):

#define _HAS_ITERATOR_DEBUGGING 0    #include <sstream>    int do_stuff(std::string const& text)  {      std::string::const_iterator i(text.end());      return 0;  }    int main()  {      std::ostringstream os;      os << "some_text";      return do_stuff(os.str());  }  

I'd found a similar post on gamdev.net that discussed having this problem in vs2005. The example program in that post compiles for me on 2008 SP1 as is - but when I modded it to use ostringstream, I was able to get the problem.

From poking around in the debugger, it looks like the library pops iterators off the stack, then later tries to use them in _Orphan_All, which is some kind of iterator checking cleanup code...

Can anyone else reproduce this problem or tell me what's going on?

Thanks!


Solution:1

I've just tried this in VS2008 on Windows XP and got a warning regarding a buffer overflow, both on a pre- and a post-SP1 VS2008.

Interestingly enough the problem seems to be centred around passing the string into do_stuff either by reference or by value - if I use the original code, it complains about the buffer overflow but if I pass the string in by value, it runs fine. This is with the multithreaded debug DLL runtime. The error disappears when you like against the static MT Debug runtime.

In both cases, precompiled headers were turned off and the files that normally generate the precompiled headers have been removed from the project.

After reading this article on MSDN I'm wondering if the problem stems from the fact that several C++ standard library classes are actually residing in the runtime library if you build with the debug DLL runtimes (just try to link a VS2008-generated binary against an earlier library and watch out for the unresolved externals to confirm this).


Solution:2

It looks like this a known bug in VS2005 that was fixed in VS2005 SP1:

Looks like this was submitted by the guy who posted about it on gamedev.net.

I'm not sure how or why it would have crept back into VS2008 (do you have headers from VS2005 that might be getting inthe way or something?)


Solution:3

Your code runs fine in Debug/Release mode on my VS2005. I have turned off precompiled headers and use the Multi-threaded DLL version of the runtime library.

Checked with VS2008 SP1 on a Vista machine (no precompiled headers, Multi-threaded DLL). Works just fine.

Check your install.


Solution:4

I reported the problem on the Microsoft website. They acknowledged the bug and say they've fixed it for the next version.

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=435483


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »