Exception ACCESS_VIOLATION 解决方案

Web (HTTP/HTML) scripts in LoadRunner are implemented using C programming language. And like always with C, you should remember about some basics. One of them is that few string handling functions can return NULL value instead of correct pointer which will definitely lead to exception like the one below:

  1. Action. c ( 7 ): Error: C interpreter run time error: Action. c  ( 7 ):  Error — memory violation : Exception ACCESS_VIOLATION received.

Basically if you see message like this, it is not any internal LoadRunner error. It means that you made a mistake in your script and you need to fix it. But let’s start from the beginning with some example:

  1. Action ( )
  2. {
  3.          char * x_p;
  4.        
  5.         lr_save_string ( "hello_world!""MESSAGE" );
  6.         x_p =  ( char * )strchr (lr_eval_string ( "{MESSAGE}" )‘ ‘ );
  7.         lr_save_string (x_p,  "MESSAGE_FROM_SP" );
  8.         lr_output_message (lr_eval_string ( "{MESSAGE_FROM_SP}" ) );
  9.        
  10.          return  0;
  11. }

This small piece of code takes parameter MESSAGE with value “hello_world”, then search for the first space character and display the string starting from that place up to the end. Function strchr() is responsible for searches for the space character. If it’s found then strchr() will return a valid pointer (something like 0xb36ac56e). But if the space is not there (which is our case since there is no space in the hello message), strchr() will return NULL which refers to 0×0 memory address location.

Such memory address is a very special address. Basically any read attempt from there is treated as incorrect operation and results in memory access violation (not only in LoadRunner).

Now, howto deal with it? If you see ACCESS_VIOLATION, in most cases it means that your LR script is working on incorrect/incomplete values. You are responsible for error handling in your scripts and you should always:

  • validate parameters values
  • check results of C functions to handle any errors, unexpected conditions
  • remember that you can’t always expect correct values and you need to handle it as well

Here is our example with fix showing howto deal with ACCESS_VIOLATION. We are calling strchr() function and checking if value returned is not NULL.

  1. Action ( )
  2. {
  3.          char * x_p;
  4.        
  5.         lr_save_string ( "hello_world!""MESSAGE" );
  6.         x_p =  ( char * )strchr (lr_eval_string ( "{MESSAGE}" )‘ ‘ );
  7.        
  8.          if (x_p )  // if the pointer is not NULL display correct message
  9.          {
  10.                 lr_save_string (x_p,  "MESSAGE_FROM_SP" );
  11.                 lr_output_message (lr_eval_string ( "{MESSAGE_FROM_SP}" ) );
  12.          }
  13.          else  //if pointer is NULL display error message
  14.          {
  15.                 lr_error_message ( "Space not found in MESSAGE parameter" );
  16.          }
  17.          return  0;
  18. }

More details about NULL pointer herehttp://en.wikipedia.org/wiki/Pointer_(computer_programming)#Null_pointer

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值