<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Waldemar's blog &#187; null</title>
	<atom:link href="http://blog.testsautomation.com/tag/null/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.testsautomation.com</link>
	<description>Live fast, die old...</description>
	<lastBuildDate>Mon, 12 Jul 2010 20:51:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Exception ACCESS_VIOLATION</title>
		<link>http://blog.testsautomation.com/2009/11/exception-access_violation/</link>
		<comments>http://blog.testsautomation.com/2009/11/exception-access_violation/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 09:33:31 +0000</pubDate>
		<dc:creator>Waldemar</dc:creator>
				<category><![CDATA[LoadRunner]]></category>
		<category><![CDATA[access_violation]]></category>
		<category><![CDATA[null]]></category>

		<guid isPermaLink="false">http://blog.testsautomation.com/?p=373</guid>
		<description><![CDATA[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 function can return NULL value instead of correct pointer which will definitely lead to exception like the one below:




Action.c&#40;7&#41;: Error: C interpreter run time error: [...]]]></description>
			<content:encoded><![CDATA[<p>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 function can return NULL value instead of correct pointer which will definitely lead to exception like the one below:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">
<ol>
<li class="li1">
<div class="de1">Action.<span class="me1">c</span><span class="br0">&#40;</span><span class="nu0">7</span><span class="br0">&#41;</span>: Error: C interpreter run time error: Action.<span class="me1">c</span> <span class="br0">&#40;</span><span class="nu0">7</span><span class="br0">&#41;</span>: &nbsp;Error &#8212; memory violation : Exception ACCESS_VIOLATION received.</div>
</li>
</ol>
</div>
</div>
<p>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&#8217;s start from the beginning with some example:</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">
<ol>
<li class="li1">
<div class="de1">Action<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">char</span> * x_p;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; lr_save_string<span class="br0">&#40;</span><span class="st0">&quot;hello_world!&quot;</span>, <span class="st0">&quot;MESSAGE&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; x_p = <span class="br0">&#40;</span><span class="kw4">char</span> *<span class="br0">&#41;</span>strchr<span class="br0">&#40;</span>lr_eval_string<span class="br0">&#40;</span><span class="st0">&quot;{MESSAGE}&quot;</span><span class="br0">&#41;</span>, <span class="st0">&#8216; &#8216;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; lr_save_string<span class="br0">&#40;</span>x_p, <span class="st0">&quot;MESSAGE_FROM_SP&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; lr_output_message<span class="br0">&#40;</span>lr_eval_string<span class="br0">&#40;</span><span class="st0">&quot;{MESSAGE_FROM_SP}&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
</div>
<p>This small piece of code takes parameter MESSAGE with value &#8220;hello_world&#8221;, 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&#8217;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&#215;0 memory address location.</p>
<p>Such memory address is a very special address. Basically any read attempt from there is threated as incorrect operation and results in memory access violation (not only in LoadRunner).</p>
<p>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:</p>
<ul>
<li>validate parameter&#8217;s values</li>
<li>check results of C functions to handle any errors, unexpected conditions</li>
<li>remember that you can&#8217;t always expect correct values and you need to handle it as well</li>
</ul>
<p>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.</p>
<div class="codesnip-container" >
<div class="codesnip" style="font-family: monospace;">
<ol>
<li class="li1">
<div class="de1">Action<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">char</span> * x_p;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; lr_save_string<span class="br0">&#40;</span><span class="st0">&quot;hello_world!&quot;</span>, <span class="st0">&quot;MESSAGE&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; x_p = <span class="br0">&#40;</span><span class="kw4">char</span> *<span class="br0">&#41;</span>strchr<span class="br0">&#40;</span>lr_eval_string<span class="br0">&#40;</span><span class="st0">&quot;{MESSAGE}&quot;</span><span class="br0">&#41;</span>, <span class="st0">&#8216; &#8216;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>x_p<span class="br0">&#41;</span> <span class="co1">// if the pointer is not NULL display correct message</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lr_save_string<span class="br0">&#40;</span>x_p, <span class="st0">&quot;MESSAGE_FROM_SP&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lr_output_message<span class="br0">&#40;</span>lr_eval_string<span class="br0">&#40;</span><span class="st0">&quot;{MESSAGE_FROM_SP}&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span> <span class="co1">//if pointer is NULL display error message</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lr_error_message<span class="br0">&#40;</span><span class="st0">&quot;Space not found in MESSAGE parameter&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="nu0">0</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
</div>
<p>More details about NULL pointer here <a href="http://en.wikipedia.org/wiki/Pointer_(computing)#The_null_pointer" target="_blank">http://en.wikipedia.org/wiki/Pointer_(computing)#The_null_pointer</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.testsautomation.com/2009/11/exception-access_violation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
