<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Help me runtime debug this code</title>
	<atom:link href="http://www.philhassey.com/blog/2012/04/26/help-me-runtime-debug-this-code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.philhassey.com/blog/2012/04/26/help-me-runtime-debug-this-code/</link>
	<description>game dev blog</description>
	<lastBuildDate>Mon, 11 Mar 2013 17:20:58 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
	<item>
		<title>By: philhassey</title>
		<link>http://www.philhassey.com/blog/2012/04/26/help-me-runtime-debug-this-code/comment-page-1/#comment-24238</link>
		<dc:creator>philhassey</dc:creator>
		<pubDate>Tue, 01 May 2012 00:18:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=1101#comment-24238</guid>
		<description>@Tim .. that wasn&#039;t a valgrind option for me .. hmm.

Also, I *really* don&#039;t think valgrind could find these errors.  Because, see the code, there&#039;s nothing invalid about accessing y[-1].  It&#039;s a valid piece of memory at the end of x[] .. And structs don&#039;t have junk memory between them.  There&#039;s nothing actually wrong with the code at all, so it has to be a static check or a run-time bounds check.  It can&#039;t be found with valgrind.

I could be wrong here, but .. I&#039;m PRETTY SURE.

-Phil</description>
		<content:encoded><![CDATA[<p>@Tim .. that wasn&#8217;t a valgrind option for me .. hmm.</p>
<p>Also, I *really* don&#8217;t think valgrind could find these errors.  Because, see the code, there&#8217;s nothing invalid about accessing y[-1].  It&#8217;s a valid piece of memory at the end of x[] .. And structs don&#8217;t have junk memory between them.  There&#8217;s nothing actually wrong with the code at all, so it has to be a static check or a run-time bounds check.  It can&#8217;t be found with valgrind.</p>
<p>I could be wrong here, but .. I&#8217;m PRETTY SURE.</p>
<p>-Phil</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Swartz</title>
		<link>http://www.philhassey.com/blog/2012/04/26/help-me-runtime-debug-this-code/comment-page-1/#comment-24237</link>
		<dc:creator>Tim Swartz</dc:creator>
		<pubDate>Tue, 01 May 2012 00:03:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=1101#comment-24237</guid>
		<description>Valgrind catches these array out of bounds errors for me when I use debugging symbols and turn on --mem-check=full.</description>
		<content:encoded><![CDATA[<p>Valgrind catches these array out of bounds errors for me when I use debugging symbols and turn on &#8211;mem-check=full.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marmakoide</title>
		<link>http://www.philhassey.com/blog/2012/04/26/help-me-runtime-debug-this-code/comment-page-1/#comment-24210</link>
		<dc:creator>Marmakoide</dc:creator>
		<pubDate>Mon, 30 Apr 2012 12:32:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=1101#comment-24210</guid>
		<description>Valgrind (for Linux) catches a whole lot of errors completly transparently, no need to touch the code at all. Just compile your code with the debug symbols.
You will catch, among others
   - Errors related to access of non-initialized memory. It can trace who/what allocated the non-initialized memory chunk.
   - Errors related to access to non-allocated memory. Like an access out of bounds</description>
		<content:encoded><![CDATA[<p>Valgrind (for Linux) catches a whole lot of errors completly transparently, no need to touch the code at all. Just compile your code with the debug symbols.<br />
You will catch, among others<br />
   &#8211; Errors related to access of non-initialized memory. It can trace who/what allocated the non-initialized memory chunk.<br />
   &#8211; Errors related to access to non-allocated memory. Like an access out of bounds</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: philhassey</title>
		<link>http://www.philhassey.com/blog/2012/04/26/help-me-runtime-debug-this-code/comment-page-1/#comment-24075</link>
		<dc:creator>philhassey</dc:creator>
		<pubDate>Thu, 26 Apr 2012 20:52:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=1101#comment-24075</guid>
		<description>@e4ch linked me to:

http://www.bugfighter-soft.com/

and

http://www.microfocus.com/products/micro-focus-developer/devpartner/index.aspx</description>
		<content:encoded><![CDATA[<p>@e4ch linked me to:</p>
<p><a href="http://www.bugfighter-soft.com/" rel="nofollow">http://www.bugfighter-soft.com/</a></p>
<p>and</p>
<p><a href="http://www.microfocus.com/products/micro-focus-developer/devpartner/index.aspx" rel="nofollow">http://www.microfocus.com/products/micro-focus-developer/devpartner/index.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: philhassey</title>
		<link>http://www.philhassey.com/blog/2012/04/26/help-me-runtime-debug-this-code/comment-page-1/#comment-24072</link>
		<dc:creator>philhassey</dc:creator>
		<pubDate>Thu, 26 Apr 2012 19:19:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=1101#comment-24072</guid>
		<description>I&#039;ve used valgrind quite a bit and that does help me catch a number of things.

I&#039;ve also used XCode analyze and that helped me catch another handful of bugs.

Neither of those catch this particular type of bug though.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve used valgrind quite a bit and that does help me catch a number of things.</p>
<p>I&#8217;ve also used XCode analyze and that helped me catch another handful of bugs.</p>
<p>Neither of those catch this particular type of bug though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jovoc</title>
		<link>http://www.philhassey.com/blog/2012/04/26/help-me-runtime-debug-this-code/comment-page-1/#comment-24070</link>
		<dc:creator>jovoc</dc:creator>
		<pubDate>Thu, 26 Apr 2012 18:54:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=1101#comment-24070</guid>
		<description>There&#039;s no way to do that without somehow modifying your code.  Once it&#039;s compiled y[-1] and y[10] are both perfectly valid lookups since they are within the range of Goods data; 

Valgrind comes pretty close and is worth a try, but I don&#039;t think it would catch that particular case. As far as the compiler is concerned that isn&#039;t actually an error.

If you can find a C interpreter, that might work in a limited scope (like unit tests).

I&#039;ve been using eastl which is nice and streamlined and avoid the allocator complexity of c++, but then again I sort of like stl in the first place. If you&#039;re using something like that you can add rangle checks and track your allocations pretty handily.

Carmack has a blog post about some industrial strength tools, I&#039;m not too familiar with these but they might be worth investigating:
http://www.altdevblogaday.com/2011/12/24/static-code-analysis/

If you want to stick to straight C arrays, since there&#039;s no hooks to instrument the array lookups, the only option I can see is to make some kind of debug macro like CHECK_RANGE(i, data) that you use near suspicious array lookups like that and could use sizeof to figure out the range.

Also, getting in the habit of using size_t instead of int for indexes will help with overflows and negative indexes.</description>
		<content:encoded><![CDATA[<p>There&#8217;s no way to do that without somehow modifying your code.  Once it&#8217;s compiled y[-1] and y[10] are both perfectly valid lookups since they are within the range of Goods data; </p>
<p>Valgrind comes pretty close and is worth a try, but I don&#8217;t think it would catch that particular case. As far as the compiler is concerned that isn&#8217;t actually an error.</p>
<p>If you can find a C interpreter, that might work in a limited scope (like unit tests).</p>
<p>I&#8217;ve been using eastl which is nice and streamlined and avoid the allocator complexity of c++, but then again I sort of like stl in the first place. If you&#8217;re using something like that you can add rangle checks and track your allocations pretty handily.</p>
<p>Carmack has a blog post about some industrial strength tools, I&#8217;m not too familiar with these but they might be worth investigating:<br />
<a href="http://www.altdevblogaday.com/2011/12/24/static-code-analysis/" rel="nofollow">http://www.altdevblogaday.com/2011/12/24/static-code-analysis/</a></p>
<p>If you want to stick to straight C arrays, since there&#8217;s no hooks to instrument the array lookups, the only option I can see is to make some kind of debug macro like CHECK_RANGE(i, data) that you use near suspicious array lookups like that and could use sizeof to figure out the range.</p>
<p>Also, getting in the habit of using size_t instead of int for indexes will help with overflows and negative indexes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: philhassey</title>
		<link>http://www.philhassey.com/blog/2012/04/26/help-me-runtime-debug-this-code/comment-page-1/#comment-24068</link>
		<dc:creator>philhassey</dc:creator>
		<pubDate>Thu, 26 Apr 2012 18:47:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.philhassey.com/blog/?p=1101#comment-24068</guid>
		<description>cppcheck works for some trivial cases.

http://sourceforge.net/apps/mediawiki/cppcheck/index.php?title=Main_Page</description>
		<content:encoded><![CDATA[<p>cppcheck works for some trivial cases.</p>
<p><a href="http://sourceforge.net/apps/mediawiki/cppcheck/index.php?title=Main_Page" rel="nofollow">http://sourceforge.net/apps/mediawiki/cppcheck/index.php?title=Main_Page</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
