Subj : BC++ 5.02 Stack Restore Bug To : borland.public.cpp.borlandcpp From : kurt jensen Date : Tue Nov 30 2004 04:41 pm for some perverse reason my Borland C++ 5.02 compiler has decided to pull funny tricks on me. after spending a week blaming the DLL vendor I stumbled onto a "situation" in the assembly representation of my compiled code. everything looks fine until you get to the "ret" statement - then we ALWAYS return to address 0x00000000. the reason is that the compiler left out one very important statement, "mov esp,ebp", i.e. the stack pointer is NEVER restored before popping ebp and 'ret'urning from the function call. because of that, we always try to return to the wrong address which is always 0 because of a parameter in a function call. anybody seen this particular problem before??? anybody have any idea what would possess the compiler to pull such a stunt??? and, more importantly, how can I convince it to properly restore the stack before returning??? TIA, Kurt below is the "C++ to Assembler" representation of the problem. notice at the end after label @156, we properly pop ebx, "mov esp,ebp" is missing, pop ebp, and 'ret'urn. @TSCOR20CaptureThread@IncrCaptureOk$qi proc near ?live1@3616: ; ; bool TSCOR20CaptureThread::IncrCaptureOk(int buffer) ; ?debug L 779 push ebp mov ebp,esp push ebx mov eax,dword ptr [ebp+12] mov ebx,dword ptr [ebp+8] ; ; { ; FlyCaptureError CameraError; ; ; if (buffer > 0) ; ?debug L 783 ?live1@3632: ; EBX = this, EAX = buffer @152: test eax,eax jle short @153 ; ; { ; CameraError = flycaptureUnlock(FCameraContext, buffer-1); ; ?debug L 785 dec eax push eax push dword ptr [ebx+22] call flycaptureUnlock ; ; if (CameraError == FLYCAPTURE_OK) ; ?debug L 786 ?live1@3664: ; EBX = this, EAX = CameraError test eax,eax jne short @155 ; ; CaptureOK++; ; ?debug L 787 ?live1@3680: ; EBX = this inc dword ptr [ebx+30] ; ; } // then, started ; ?debug L 788 ?live1@3696: ; jmp short @155 ; ; else ; { ; CaptureOK++; ; ?debug L 791 ?live1@3712: ; EBX = this @153: inc dword ptr [ebx+30] ; ; } // else ; ; return true; ; ?debug L 794 ?live1@3728: ; @155: mov al,1 ; ; } // TSCOR20CaptureThread::IncrCaptureOk() ; ?debug L 795 @157: @156: pop ebx pop ebp ret ?debug L 0 @TSCOR20CaptureThread@IncrCaptureOk$qi endp .