Simple stack overflow example

Question: Take a simple stack overflow example in C/C++

Answer:

The following code will cause stack overflow since Calc() function is recursively called without base condition.

#include 

int Calc(int i, int j)
{
    int a = i + j;
    int b = Calc(a, i);
    return b;
}

int main()
{
    int a = 1;
    int b = 2;

    int res = Calc(a, b);
    std::cout << res;
}         

When running in WinDbg, "Stack overflow - code c00000fd" error will be detected. And "kb" command will show recursive call stack frames (00 ~ ff) as below.

0:000> g
(1d14.3904): Stack overflow - code c00000fd (first chance)  <=======
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
*** WARNING: Unable to verify checksum for StackOver.exe
eax=31ae7e92 ebx=00efe000 ecx=572f5f85 edx=00000001 esi=00c11339 edi=00ce3124
eip=00c11719 esp=00ce2f58 ebp=00ce3030 iopl=0         nv up ei pl nz ac po nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010212
StackOver!Calc+0x9:
00c11719 53              push    ebx

0:000> kb
 # ChildEBP RetAddr  Args to Child              
00 00ce3030 00c1174e 572f5f85 31ae7e92 00ce3218 StackOver!Calc+0x9 
01 00ce3124 00c1174e 31ae7e92 2580e0f3 00ce330c StackOver!Calc+0x3e 
02 00ce3218 00c1174e 2580e0f3 0c2d9d9f 00ce3400 StackOver!Calc+0x3e 
03 00ce330c 00c1174e 0c2d9d9f 19534354 00ce34f4 StackOver!Calc+0x3e 
...
...
fd 00cf2154 00c1174e 49458b12 913a086b 00cf233c StackOver!Calc+0x3e 
fe 00cf2248 00c1174e 913a086b b80b82a7 00cf2430 StackOver!Calc+0x3e 
ff 00cf233c 00c1174e b80b82a7 d92e85c4 00cf2524 StackOver!Calc+0x3e