MFC 错误仅在发布模式下"Failed to create an empty document"

MFC error "Failed to create an empty document" in Release mode only

本文关键字:Failed to create document empty an 模式 错误 布模式 MFC      更新时间:2023-10-16

我在MFC/SDI和Visual Studio 2008下运行一个应用程序。

我仅在发布模式下收到错误"无法创建空文档"。我发现有问题的代码是我在下面向您展示的。仅当输入参数是电子邮件字符串即 xyz@yahoo.com 时,才会触发该错误。同样在调试模式下,它工作得很好。

有人可以给我解释为什么会发生这种情况吗?

void CUtils::RemoveEndingSlash(CString *str) {

    if (str->GetAt(str->GetLength()-1) == '/') {
        *str = str->Left(str->GetLength() - 1);
    }
}

确切的违规代码是

str->GetAt(x).

我解决了使用输入参数按值而不是按引用更改上述代码的问题。

问候

好的解决了

缓冲区溢出,因为某些调用方在传递空字符串之前。

我没有检查空字符串,因此我得到了缓冲区溢出。

相关文章: