locked
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. RRS feed

  • Question

  • I have a problem with my proto block of my virtual class, im trying to call virtual function, but get ESP crash. Here is code with all comments:

    #include <iostream>
    
    class _V {
    public:
    	virtual void foo(const char* _msg) {
    		std::cout << _msg << std::endl;
    	}
    };
    
    class _A : public _V {  };
    
    typedef void ( *foo_t ) ( const char* );
    
    int main(int argc, char** argv)
    {
    	const char* _msg = "Hello World";
    
    	_V* _a = new _A;
    
    	// Ok
    	_a->foo(_msg);
    
    /*
    	00CE7064  mov         esi,esp  
    	00CE7066  mov         eax,dword ptr [_msg]  
    	00CE7069  push        eax  
    	00CE706A  mov         ecx,dword ptr [_a]  
    	00CE706D  mov         edx,dword ptr [ecx]  
    	00CE706F  mov         ecx,dword ptr [_a]  
    	00CE7072  mov         eax,dword ptr [edx]  
    	00CE7074  call        eax  
    	00CE7076  cmp         esi,esp  
    	00CE7078  call        __RTC_CheckEsp (0CE3287h)  
    */
    
    	// Ok
    	__asm
    	{
    		mov  eax, _a
    		mov  ebx, [eax]
    		mov  ebx, [ebx]
    		mov  ecx, eax
    		mov  edx, _msg
    		push edx
    		call ebx
    	}
    
    	// Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. 
    	(**(foo_t**)_a)(_msg);
    
    /*
    	00A0708C  mov         esi,esp  
    	00A0708E  mov         eax,dword ptr [_msg]  
    	00A07091  push        eax  
    	00A07092  mov         ecx,dword ptr [_a]  
    	00A07095  mov         edx,dword ptr [ecx]  
    	00A07097  mov         eax,dword ptr [edx]  
    	00A07099  call        eax  
    	00A0709B  add         esp,4  
    	00A0709E  cmp         esi,esp  
    	00A070A0  call        __RTC_CheckEsp (0A03287h)  
    */
    
    	return 0;
    }

    Sunday, July 7, 2013 9:58 PM