Skip to main content

Error : The value of ESP was not properly saved across a function call.

Sometimes you may face such a error while executing your program written in C++: 
  
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call.
or 
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.


The above mentioned error you will get only if you are running program compiled in debug mode. If the program is compiled in release mode you will get Exception code: 0xc0000005 which is Access Violation exception. 


Cause of error:


Consider a situation,  you have declared one function with one calling convention ( for example __cdecl ). You do LoadLibrary, get the proc address, now if you are calling function with other  calling convention such as ( __stdcall ) by mistake. Function executed, your task completed sucessfully. Everything will work fine until  you try to use the return value of the function.


The error Access Violation occurred because you have declared function with __cdecl calling convention, means function has its own stack clean up code. And you are trying to access the function with __stdcall which means, function does not code to cleanup the stack, so compiler will insure that after function returns the callee will celanup the stack, which eventually means there are two stack cleaner exists. 
Now function execution will complete as expected but then the time will come to assign the value of return variable which is present in the ESP register due to two cleanup codes the second time asses to the ESP will be evaluated in the exception as register is already cleaned by one of the cleaner. 

Comments

Popular posts from this blog

How to boot Samsung Galaxy SL( GT-I9003) in recovery mode

** I Will Not responsible for any damage done with use of below mentioned methods. ** Power off your Samsung Galaxy SL (GT- I9003) to start in recovery mode. Once you have power off the phone, press and Hold Volume UP and Home button. Make sure you have hold volume up, don't press in  the middle of the volume buttons.  Now keep pressing these two buttons(VOL UP + HOME) and presspower button for 2-3 seconds. Release only power button, but keep pressing Volume Up + Home Button, until you see the screen shown below. Once you see recovery screen release the Home button else your phone will restart as first selected option will be restart and pressing home will make that happen.

In the recovery mode, volume up & down act as a up scroll and down scroll buttons, by pressing Home button you will be able to click the selected option.

How to flash CWM Recovery to Samsung Galaxy SL( GT-I9003) using Odin

** I Will Not responsible for any damage done with use of below mentioned methods. ** To flash the CWM recovery to your Samsung Galaxy SL you will require to following things in place: Odin  : you can download it from here.CWM Recovery image : you can download it from here. Thanks to XDA-developers. USB driver to connect your phone with computer. Install Samsung Kias so it will install the USB driver. Once you have downloaded above required items and installed the USB driver, reboot you phone to download mode. You can read how to reboot phone in download mode from here. Now connect the phone with USB cable to computer. 
Extract the Odin from the zip file that you have downloaded at some location on your computer and launch the Odin executable by double clicking it. Wait for Odin to detect your phone.You will be able to see it in yellow once detected on odin screen as shown below.
Click the PDA button to select the CWM recovery image. Once you have selected the recovery image, check the od…

Exception handling with RestTemplate

Spring framework offers RestTemplate for consuming RESTful services. Recently I used RestTemplate for consuming one of the third party RESTful service.

RestTemplate offers 'ResponseErrorHandler'; which you can extend to decide which are errors for you and how to handle those error. You can override hasError and handleError methods of ResponseErrorHandler.
In handleError you can throw customException if you want, as outlined in below code.

import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpResponse; import org.springframework.web.client.ResponseErrorHandler; import java.io.IOException; public class RestTemplateErrorHandler implements ResponseErrorHandler { @Override public void handleError(ClientHttpResponse response) throws IOException { throw new MyCustomException(response.getStatusText(), response.getStatusCode()); } @Override public boolean hasError(ClientHttpResponse response) throws IOException …