gpt4 book ai didi

c++ - main() 之前的堆栈溢出异常

转载 作者:可可西里 更新时间:2023-11-01 17:58:44 26 4
gpt4 key购买 nike

这是我在 stackoverflow 上的第一个问题,所以我会尽量具体一点。我在论坛上搜索了任何相关主题,但没有成功。不管怎样,这里是:

我正在使用 Visual Studio 2005。我遇到了堆栈溢出异常:IHR.exe 中 0x775715de 处未处理的异常:0xC00000FD:堆栈溢出。 ,在尝试调试我的项目时。调用堆栈没有帮助,因为它在 ntdll.dll 处停止,甚至在进入 main() 函数之前。

起初我怀疑这可能是编译设置的问题,但是当我将在我的计算机上编译的可执行文件发送到第二台计算机时,它可以正常运行,只是不会在我的机器上运行。

同样的情况反过来发生,我在第二台计算机上编译了可执行文件,它可以在第二台计算机上运行良好。但是当我试图在我的电脑上运行在第二台电脑上编译好的可执行文件时,却无法运行。出现的只是一个空白的命令提示符和一条 Windows 消息,说明程序没有响应。

我使用的是 Windows 7 Professional SP1,64 位。另一台计算机具有相同的操作系统版本。由于公司政策,我不能在这里发布任何源代码,但无论如何我认为它与源代码没有任何关系。我怀疑这可能是运行时环境的问题。感谢任何帮助。谢谢。

这是调用堆栈中的所有内容:

->ntdll.dll!775715de()  
[Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]
ntdll.dll!775715de()
ntdll.dll!7756014e()

感谢@WhozCraig 的建议,我设法在调用堆栈上获得了更有意义的消息。仍然难过。

IHR.exe!_mbscmp(const unsigned char * s1=0x00fe8c10, const unsigned char * s2=0x00fe8c10) Line 84 + 0xf bytes
IHR.exe!_mbscmp(const unsigned char * s1=0x00fe8c10, const unsigned char * s2=0x00fe8c10) Line 84 + 0xf bytes
IHR.exe!strcmp(const char * _s1=0x00fe8c10, const char * _s2=0x00fe8c10) Line 1646 + 0x2b bytes
IHR.exe!_mbscmp_l(const unsigned char * s1=0x00fe8c10, const unsigned char * s2=0x00fe8c10, localeinfo_struct * plocinfo=0x00000000) Line 58 + 0xd bytes
IHR.exe!_mbscmp(const unsigned char * s1=0x00fe8c10, const unsigned char * s2=0x00fe8c10) Line 84 + 0xf bytes
IHR.exe!strcmp(const char * _s1=0x00fe8c10, const char * _s2=0x00fe8c10) Line 1646 + 0x2b bytes

还有一些,导致上面的堆栈

IHR.exe!_mbscmp_l(const unsigned char * s1=0x00fe8c10, const unsigned char * s2=0x00fe8c10, localeinfo_struct * plocinfo=0x00000000)  Line 58 + 0xd bytes   C++
IHR.exe!_mbscmp(const unsigned char * s1=0x00fe8c10, const unsigned char * s2=0x00fe8c10) Line 84 + 0xf bytes C++
IHR.exe!strcmp(const char * _s1=0x00fe8c10, const char * _s2=0x00fe8c10) Line 1646 + 0x2b bytes
IHR.exe!_setlocale_get_all(threadlocaleinfostruct * ploci=0x002f13a0) Line 1147 + 0x24 bytes
IHR.exe!_setlocale_nolock(threadlocaleinfostruct * ploci=0x002f13a0, int _category=0, const char * _locale=0x00000000) Line 966 + 0x9 bytes C

IHR.exe!setlocale(int _category=0, const char * _locale=0x00000000) Line 826 + 0x1b bytes
IHR.exe!std::_Locinfo::_Locinfo_ctor(std::_Locinfo * pLocinfo=0x0018f8f8, const char * locname=0x00ea591c) Line 192 + 0x9 bytes
IHR.exe!std::_Locinfo::_Locinfo(const char * _Pch=0x00ea591c) Line 78 + 0xd bytes
IHR.exe!std::ctype::ctype(const short * _Table=0x00000000, bool _Deletetable=false, unsigned int _Refs=0) Line 1740 + 0x10 bytes
IHR.exe!std::ctype::_Getcat(const std::locale::facet * * _Ppf=0x0018fbd8) Line 1760 + 0x4d bytes IHR.exe!std::use_facet >(const std::locale & _Loc={...}) Line 478 + 0x9 bytes IHR.exe!std::basic_ios >::widen(char _Byte=' ') Line 124 + 0x34 bytes
IHR.exe!std::basic_ios >::init(std::basic_streambuf > * _Strbuf=0x00ff7908, bool _Isstd=false) Line 135 + 0xa bytes
IHR.exe!std::basic_ostream >::basic_ostream >(std::basic_streambuf > * _Strbuf=0x00ff7908, bool _Isstd=false) Line 53
IHR.exe!std::`dynamic initializer for 'cout''() Line 13 + 0x16 bytes IHR.exe!_initterm(void (void)* * pfbegin=0x00e8d10c, void (void)* * pfend=0x00e9dca0) Line 855 IHR.exe!_cinit(int initFloatingPrecision=1) Line 293 + 0xf bytes
IHR.exe!tmainCRTStartup() Line 310 + 0x7 bytes
IHR.exe!mainCRTStartup() Line 196
kernel32.dll!@BaseThreadInitThunk@12() + 0x12 bytes
ntdll.dll!
RtlUserThreadStart@8() + 0x27 bytes
ntdll.dll!
_RtlUserThreadStart@8() + 0x1b bytes

它不断重复调用 strcmp、mbscmp、mbscmp_l,直到遇到堆栈溢出异常。

更新(2013 年 4 月 11 日):我找到了导致问题的那一行,但我仍然完全不知道为什么会导致它。这是strcmp的用法。

struct Foo
{
char text[4];
bool operator < (const Foo &rhs) const
{
return strcmp(text, rhs.text) < 0;
}
}

当这个strcmp被注释掉的时候。程序没有崩溃。处理此类问题的任何想法或经验?同一个程序在其他机器上仍然可以正常运行,但由于这条线,只会在我的机器上崩溃。 other strcmp 在整个程序中使用没有问题。谢谢

最佳答案

很可能您有全局/静态变量,并且它们试图在您运行 main 之前进行初始化。实际初始化的顺序可能不是您所期望的,就像您将它们放在不同的文件中一样,没有办法告诉它们应该以什么顺序创建。

要么删除这些变量,要么将它们安排到同一个文件中。

关于c++ - main() 之前的堆栈溢出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15426285/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com