Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stack overflow exception before main()

this is my first question here on stackoverflow so I'll try to be specific. I searched the forums for any related topic but no luck. Anyway here goes:

I'm using Visual Studio 2005.I encountered a stack overflow exception :Unhandled exception at 0x775715de in IHR.exe: 0xC00000FD: Stack overflow. ,when attempting to debug my project. The call stack does not help as it stops at ntdll.dll, before even entering the main() function.

At first I suspected that it may be a compilation settings thing, but when I sent the executable compiled on my computer to a second computer, it could run fine, it just won't run on my machine.

The same happens in reverse, I compiled the executable on the second computer, it could run fine on that. But when I tried to run the executable that was compiled on the second computer on my computer, it couldn't run. All that appeared was a blank command prompt and a windows message saying the program was not responding.

I'm using Windows 7 Professional SP1, 64 bit. The other computer has the same OS version. Due to company policy, I can't post any source code here, but anyway I don't think it has anything to do with the source code. I suspect it may be a problem in the runtime environment. Appreciate any help. Thanks.

Here's all there is on the call stack:

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

Thanks to @WhozCraig's suggestion, I have managed to get a more meaningful message on the call stack. Still stumped though.

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

here's some more, leading up to the stack above

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

It keeps repeatedly calling strcmp, mbscmp, mbscmp_l until it hits a stack overflow exception.

Update(11 April 2013): I've found the line that causes the problem, but am still totally clueless on why it's causing it. It's the usage of a strcmp.

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

When this strcmp was commented out. The program did not crash. Any ideas or experience with dealing with such a problem? The same program still runs fine on other machines, but only crashes on my machine due to this line. other strcmp is used throughout the program with no issue. Thanks

like image 442
mikevil14rin Avatar asked Mar 15 '13 06:03

mikevil14rin


People also ask

How do I fix stack overflow exception?

Setting the size of the stack or the maximum depth value of the recursion is allowed in most of the programming languages. Now that we have an opportunity to set the value of the depth of the stack, we have to set to a value as small as possible and observe the output.

What causes a stack overflow exception?

A StackOverflowException is thrown when the execution stack overflows because it contains too many nested method calls. using System; namespace temp { class Program { static void Main(string[] args) { Main(args); // Oops, this recursion won't stop. } } }

When stack overflow happens in C#?

This means when you get the value of val , your code goes into a never ending loop as the result references itself. In . Net this will eventually cause a stack overflow exception. Good explanation, +5!

How does Java handle stack overflow exception?

Solution. The simplest solution is to carefully inspect the stack trace and detect the repeating pattern of line numbers. These line numbers indicate the code that is being recursively called. Once you detect these lines, look for the terminating condition (base condition) for the recursive calls.


1 Answers

It is likely that you have global/static variables and they are trying to initialize before you run main. Probably the order of actual initialization is not what you expect, as if you have them in different files, there is no way to tell in which order they should be created.

Either remove those variables or arrange them into the same file.

like image 96
Valeri Atamaniouk Avatar answered Oct 12 '22 18:10

Valeri Atamaniouk