简体   繁体   English

在vs2008 SP1中禁用已检查的迭代器时出现问题(_HAS_ITERATOR_DEBUGGING = 0)

[英]Problem when disabling checked iterators in vs2008 SP1 (_HAS_ITERATOR_DEBUGGING=0)

I've been having some trouble with vs2008 SP1 running in debug mode when I try to disable checked iterators. 当我尝试禁用已检查的迭代器时,我在调试模式下运行vs2008 SP1时遇到了一些麻烦。 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. 我在gamdev.net上发现了类似的帖子 ,讨论了在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. 该帖子中的示例程序按原样编译为2008 SP1 - 但是当我将其修改为使用ostringstream时,我能够解决问题。

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... 从调试器中调试来看,它看起来像是从堆栈中弹出迭代器,然后尝试在_Orphan_All中使用它们,这是某种迭代器检查清理代码......

Can anyone else reproduce this problem or tell me what's going on? 任何人都可以重现这个问题或者告诉我发生了什么事吗?

Thanks! 谢谢!

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. 我刚刚在Windows XP上的VS2008中尝试了这个,并且在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. 有趣的是,问题似乎集中在通过引用或值将字符串传递给do_stuff - 如果我使用原始代码,它会抱怨缓冲区溢出但是如果我按传递字符串,它运行正常。 This is with the multithreaded debug DLL runtime. 这是多线程调试DLL运行时。 The error disappears when you like against the static MT Debug runtime. 当您喜欢静态MT Debug运行时时,错误消失。

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). MSDN上阅读这篇文章后,我想知道问题是否源于几个C ++标准库类实际上驻留在运行时库中,如果你使用调试DLL运行时构建(只是尝试将VS2008生成的二进制文件链接到一个早期的图书馆,并留意未解决的外部,以确认这一点)。

It looks like this a known bug in VS2005 that was fixed in VS2005 SP1: 看起来这是VS2005中已知的错误,已在VS2005 SP1中修复:

Looks like this was submitted by the guy who posted about it on gamedev.net. 看起来这是由在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?) 我不确定它是如何或为什么会悄悄回到VS2008(你有VS2005的标题,可能会有什么方法吗?)

Your code runs fine in Debug/Release mode on my VS2005. 您的代码在我的VS2005上的调试/发布模式下运行良好。 I have turned off precompiled headers and use the Multi-threaded DLL version of the runtime library. 我已关闭预编译的头文件并使用运行时库的多线程DLL版本。

Checked with VS2008 SP1 on a Vista machine (no precompiled headers, Multi-threaded DLL). 在Vista计算机上检查VS2008 SP1(没有预编译头,多线程DLL)。 Works just fine. 工作得很好。

Check your install. 检查您的安装。

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 http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=435483

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM