Answer the question
In order to leave comments, you need to log in
Strange behavior of the Intel C++ compiler?
While parsing one working project, I ran into a strange problem: the debug version "fell" with the error "Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call".
I began to figure it out ... I
came to this code, which crashes for absolutely the same reason:
#include <string.h>
void test()
{
char a[10];
char b[] = "test";
strcpy_s(a, b);
__try
{
}
__except(1)
{
}
}
int main()
{
test();
return 0;
}
push -1
push OFFSET FLAT: _try_info_pack0
push OFFSET FLAT: __except_handler3
push eax
sub esp, 3Ch
mov DWORD PTR [ebp - 18h], esp
add esp, 0
call strcpy_s
add esp, 8
mov esp, DWORD PTR [ebp - 18h]
add esp, 44h
cmp ebp, esp
call __RTC_CheckEsp
push eax;
mov dword ptr[ebp - 18h], esp;
pop eax;
mov esp, dword ptr[ebp - 18h];
cmp esp, ebp; // !!!!
__asm
{
nop;
}
push -1
push OFFSET FLAT: _try_info_pack0
push OFFSET FLAT: __except_handler3
push eax
sub esp, 34h
mov DWORD PTR [ebp - 18h], esp
add esp, -8
call strcpy_s
add esp, 8
mov esp, DWORD PTR [ebp - 18h]
add esp, 44h
cmp ebp, esp
call __RTC_CheckEsp
mov dword ptr[ebp - 18h], esp;
push eax;
pop eax;
mov esp, dword ptr[ebp - 18h];
cmp esp, ebp; // Теперь всё хорошо
void t2(int a)
{
return;
}
void t1()
{
t2(10);
__try
{
}
__except(1)
{
}
}
int main()
{
t1();
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question