<?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>&#62;kloctalk&#187; Nasty Bugs</title>
	<atom:link href="http://www.klocwork.com/blog/category/nasty-bugs/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.klocwork.com/blog</link>
	<description>&#62;kloctalk is a blog and a community for software development professionals who create and maintain mission-critical software and the challenges they face on a daily basis.</description>
	<lastBuildDate>Tue, 24 Jan 2012 14:57:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>To report, or not to report&#8230;</title>
		<link>http://www.klocwork.com/blog/2011/06/to-report-or-not-to-report/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=to-report-or-not-to-report</link>
		<comments>http://www.klocwork.com/blog/2011/06/to-report-or-not-to-report/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 20:10:20 +0000</pubDate>
		<dc:creator>Gwyn Fisher</dc:creator>
				<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[Software Quality]]></category>
		<category><![CDATA[Software Security]]></category>
		<category><![CDATA[Static Analysis]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=1333</guid>
		<description><![CDATA[Creating a source code analysis (SCA) engine is a balancing act, a decision process of where you believe the most value can be found along the spectrum that is the signal-to-noise ratio of the detection process. At one end lies the realm of massive noise and hopefully complete coverage, whilst at the other is the [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright" style="margin-left: 5px; margin-right: 5px;" src="http://images.all-free-download.com/images/graphiclarge/balance_scale_clip_art_10655.jpg" alt="Balance" width="425" height="274" />Creating a source code analysis (SCA) engine is a balancing act, a decision process of where you believe the most value can be found along the spectrum that is the signal-to-noise ratio of the detection process. At one end lies the realm of massive noise and hopefully complete coverage, whilst at the other is the quiet calm of the theoretically useful but ultimately useless realm of no noise, but ultimately no signal either.</p>
<p>That may sound counter-intuitive. Shouldn’t a zero noise point on the spectrum be accompanied by an infinitely strong signal? Perhaps in the world of DSP this is true, but in the world of SCA reducing noise comes right along with a reduction in detection capability &#8211; it’s unfortunately almost a straight-line correlation.</p>
<p>So if we assume that we’re trying to balance a couple of dials on our theoretical tuner, we might start by reducing or dampening noise – it’s the most obvious place to start, after all. Nobody likes to listen to their favorite FM station through the curtain of hissing and popping that accompanies the act of driving through a major city.  Likewise no developer likes sifting through a long list of bogus detection errors in order to find the hidden gems. But to drag out the analogy, assume that the only way of reducing hiss on your FM signal is to turn down the volume… now you’ve got less hiss, but also less Bruce Springsteen goodness to accompany it.</p>
<p>Balance is what we need here, obviously. Enough Boss to make us ignore the hiss, or to put it in a more SCA-like context, enough interesting bugs to make us ignore the incorrect, or the irrelevant (correct detections on the part of the engine that the developer just doesn’t care about, e.g. low memory conditions in a memory-insensitive environment).</p>
<p>Consider the following simple example that clearly lies &#8220;on the line&#8221;:</p>
<pre><span style="font-size: small;"><span style="font-family: courier new,courier;">    void foo(char* s, int a)</span><span style="font-family: courier new,courier;">
    {
</span><span style="font-family: courier new,courier;">        char* s1 = s;
</span><span style="font-family: courier new,courier;">        if( a &gt; 0 )
</span><span style="font-family: courier new,courier;">            *s1 = 'a';   // potentially use an uninitialized ‘s1’</span><span style="font-family: courier new,courier;">
    }
</span><span style="font-family: courier new,courier;">
    void bar(int m)
    {
        char *s;
        foo(s, m);       // s is not initialized prior to calling ‘foo’
    }</span></span></pre>
<p>So&#8230; to report, or not to report?</p>
<p>Lacking any other information, it is obvious that function ‘foo’ interacts under certain situations (when parameter ‘a’ is positive) with parameter ‘s’ (aliased as local variable ‘s1’). As we have no knowledge about the provenance of parameter ‘s’ when analyzing ‘foo’, however, there’s nothing here to cause a report and so we squirrel away the knowledge of what ‘foo’ does for later use.</p>
<p>When analyzing ‘bar’ we know what ‘foo’ does, and we know we’ve got an uninitialized local pointer, ‘s’. But again we’re lacking enough knowledge to know the valid values, or ranges, that parameter ‘m’ may take. There are definitely a set of circumstances here in which we know a problem will occur (if parameter ‘m’ is positive), and a set of circumstances in which we know a problem will not occur (if parameter ‘m’ is zero or negative) – this much is encoded in the functional behavior of ‘foo’. But is it a defect, or should we filter out the report in favor of providing only those situations in which we can be “sure” the bug not only exists, but can be proven to be exercised?</p>
<p>There’s the art of balance in a nut-shell, and it revolves around the phrase “lacking any other information.” In the ideal world, lacking any restrictions in terms of time, memory or computing power (or indeed actual from-the-wall power, as we have to worry about now), we might defer all such decisions until we categorically know that a particular data value is passed down the call graph far enough to get to ‘foo’. But in the real world of multi-million LOC projects, that approach simply can’t scale.</p>
<p>And so, calling on balance as our friend, we can bias a localized decision to report or not, given that we know to at least one order of approximation that bad things could happen here. Different engines pronounce that bias differently, leading to one of the greatest divides between prevalent solutions.</p>
<p>Now ask yourself, as the developer, is it a worthy report if you know that 10 levels up the call graph there’s a check on what eventually becomes parameter ‘m’ to ensure that it’s never positive? Perhaps you’d automatically classify this as a false positive and, annoyed at the tool, move onto the next report. Or perhaps, seeing the size of the gap in the call graph, you might just choose to code defensively, initializing ‘s’ to NULL in ‘bar’ and adding guard code to &#8216;foo&#8217; because, hey, you never know.</p>
<p>And as we’ve all seen so many times over the years, “you never know” might just as well be written “and so it came to pass&#8230;”</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2011/06/to-report-or-not-to-report/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stack smashing</title>
		<link>http://www.klocwork.com/blog/2011/05/stack-smashing/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=stack-smashing</link>
		<comments>http://www.klocwork.com/blog/2011/05/stack-smashing/#comments</comments>
		<pubDate>Tue, 03 May 2011 19:41:24 +0000</pubDate>
		<dc:creator>Alen Zukich</dc:creator>
				<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[buffer overflows]]></category>
		<category><![CDATA[memory overflows]]></category>
		<category><![CDATA[stack corruption]]></category>
		<category><![CDATA[stack smashing]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=1316</guid>
		<description><![CDATA[A while ago I talked about memory overflows.  Now in this latest instalment, as we look at more interesting bugs, I&#8217;ve come across a new example.  Here is a situation described by a customer as &#8220;stack smashing&#8221;, which occurs when you copy a string of unknown length into a fixed buffer size. #include &#60;stdio.h&#62;; void [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I talked about <a href="http://www.klocwork.com/blog/2011/04/memory-overflows/" target="_blank">memory overflows</a>.  Now in this latest instalment, as we look at more interesting bugs, I&#8217;ve come across a new example.  Here is a situation described by a customer as &#8220;stack smashing&#8221;, which occurs when you copy a string of unknown length into a fixed buffer size.</p>
<pre>
<pre class="brush: cpp; title: ;">#include &lt;stdio.h&gt;;

void foo(char * v) {
    char buffer[10];
    if(v != NULL)
   {
            memcpy(buffer, v,strlen(v));
    }
}

int main (int argc, char ** argv)
{
    foo(argv[1]);
    foo(&quot;the longest string you can find&quot;);
    return 0;
}</pre>
</pre>
<p>Just like the <a href="http://www.klocwork.com/blog/2011/04/memory-overflows/" target="_blank">memory overflow</a> post this is another form of a <a href="http://en.wikipedia.org/wiki/Buffer_overflow" target="_blank">buffer overflow</a>.  So there you have it, just more terminology to describe bad things in your code.  <a href="http://www.klocwork.com/blog/author/gwyn-fisher/" target="_blank">Gwyn</a> promises to give a follow up to these posts with some details on how this general area (stack corruption, tainted sources, etc.) can be exploited.  Can&#8217;t wait to see that.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2011/05/stack-smashing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memory overflows</title>
		<link>http://www.klocwork.com/blog/2011/04/memory-overflows/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=memory-overflows</link>
		<comments>http://www.klocwork.com/blog/2011/04/memory-overflows/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 13:53:58 +0000</pubDate>
		<dc:creator>Alen Zukich</dc:creator>
				<category><![CDATA[General Coding]]></category>
		<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[memory overflows]]></category>
		<category><![CDATA[source code analysis]]></category>
		<category><![CDATA[stack corruption]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=1279</guid>
		<description><![CDATA[A few years back a customer said they had all kinds of trouble with bugs corrupting their stack.  Even though they asked if source code analysis tools could help find stack corruption, once we got an example, we found that they were really looking for was memory overflows.  So what on earth is a memory [...]]]></description>
			<content:encoded><![CDATA[<p>A few years back a customer said they had all kinds of trouble with bugs corrupting their stack.  Even though they asked if source code analysis tools could help find stack corruption, once we got an example, we found that they were really looking for was memory overflows.  So what on earth is a memory overflow?  Does that even exist?</p>
<p>Yes, except it is probably not what you&#8217;re thinking, it&#8217;s not the same as a <a href="http://en.wikipedia.org/wiki/Memory_leak" target="_blank">memory leak</a>;  a memory overflow is quite <a href="http://www.blurtit.com/q551100.html" target="_blank">different</a>.  A memory overflow is really just a form of a <a href="http://en.wikipedia.org/wiki/Buffer_overflow" target="_blank">buffer overflow</a>.  The impact of memory overflow is unexpected behavior or program failure.   Take this example:</p>
<pre class="brush: cpp; title: ;">
#include &lt;stdio.h&gt;
typedef struct s1_ {
   int i;
   int j;
   char arr[10];
}s1;

typedef struct s2_ {
   char b[20];
   char c[40];
}s2;

main()
{
   s1 block1;
   memset(&amp;block1, 0, sizeof(s2));
   block1.i =1;
}
</pre>
<p>Here we have the case of incorrectly using &#8216;memset&#8217; at line 16 where &#8216;sizeof(s2)&#8217; is bigger than &#8216;block1&#8242;.  In fact, going back to this customer revealed that the issue was due to memset clearing much more area than intended.  If you&#8217;re using static analysis or source code analysis tools then you are probably covered by this.  You will find this type of issue usually in the &#8220;buffer overflow&#8221; category.</p>
<p>So, are you free of your memory overflows?</p>
<p style="text-align: center;"><a href="http://www.klocwork.com/blog/wp-content/uploads/2011/04/2009-08-17-memory-corruption.png"><img class="aligncenter size-full wp-image-1282" title="2009-08-17-memory-corruption" src="http://www.klocwork.com/blog/wp-content/uploads/2011/04/2009-08-17-memory-corruption.png" alt="" width="900" height="364" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2011/04/memory-overflows/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Another resource leak</title>
		<link>http://www.klocwork.com/blog/2011/03/another-resource-leak/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=another-resource-leak</link>
		<comments>http://www.klocwork.com/blog/2011/03/another-resource-leak/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 16:30:13 +0000</pubDate>
		<dc:creator>Alen Zukich</dc:creator>
				<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[resource leaks]]></category>
		<category><![CDATA[Static Analysis]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=1250</guid>
		<description><![CDATA[It happened again.  For what seems like the 100th time, someone reports to me that they are seeing a number of false positive reports on the resource leak checker.  For those not familiar with a resource leak, take a look at a previous post.  Although resource leaks apply across most languages, the place where this [...]]]></description>
			<content:encoded><![CDATA[<p>It happened again.  For what seems like the 100th time, someone reports to me that they are seeing a number of false positive reports on the resource leak checker.  For those not familiar with a resource leak, take a look at a previous <a href="http://www.klocwork.com/blog/2009/02/resource-leaks-in-c/" target="_blank">post</a>.  Although resource leaks apply across most languages, the place where this question keeps coming  up seems to always be in Java or C# code.  My last query came from Java code, so we will use that as an example.  Here was a report where the FileInputSteam is not closed on exit.</p>
<pre><code>FileChannel sch = new FileInputStream(...);
FileChannel dch = new FileOutputStream(...);
try{
   ...
} catch (...) {
   ...
} finally {
   try {
      sch.close();
   }
}
...</code></pre>
<p>Do you see this issue?  Clearly, they close the FileInputStream in the finally block.  The problem is that you can still throw an exception when you try to create a FileOutputStream.  The simple fix is to encompass the FileInputStream and FileOutputStream in the try/catch blocks.</p>
<p>Static analysis tools are great for finding bugs like this resource leak.  In this case, the report that a FileInputStream is not closed on exit wasn&#8217;t enough information to debug this.  This brings us to a very important discussion with static analysis tools&#8211;trace.</p>
<p>Gone are the days where a static analysis tool reports a bug at line X with no context.  Today you get detailed traces.  The trace contains conditions and assignments to give you clues about why the tool is identifying a bug.  In this example below, identifying the &#8220;source&#8221; and &#8220;sink&#8221; of any defect will help you trace through the start/end of the control flow.</p>
<p><a href="http://www.klocwork.com/blog/wp-content/uploads/2011/02/trace.png"><img class="alignleft size-full wp-image-1251" title="trace" src="http://www.klocwork.com/blog/wp-content/uploads/2011/02/trace.png" alt="" width="298" height="122" /></a></p>
<p><br class="spacer_" /></p>
<p>More importantly in the case of Java, here we have a clear understanding where exceptions are thrown.  This would have helped tremendously for the example above.</p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
<p>Detailed traces are very important and can do many things for individual checkers.  So whatever you do, don&#8217;t just look at the bug description, pay attention to the trace!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2011/03/another-resource-leak/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dealing with a different type of backlog&#8230;your bug backlog</title>
		<link>http://www.klocwork.com/blog/2011/02/dealing-with-a-different-type-of-backlog-your-bug-backlog/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dealing-with-a-different-type-of-backlog-your-bug-backlog</link>
		<comments>http://www.klocwork.com/blog/2011/02/dealing-with-a-different-type-of-backlog-your-bug-backlog/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 14:00:53 +0000</pubDate>
		<dc:creator>Todd Landry</dc:creator>
				<category><![CDATA[General Coding]]></category>
		<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[Software Quality]]></category>
		<category><![CDATA[backlog]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[defect detection]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[source code analysis]]></category>
		<category><![CDATA[Static Analysis]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=1230</guid>
		<description><![CDATA[As a product manager, the only backlog I typically care about is my product backlog. Do I have the right stories in there? Do the stories have enough detail? Are they properly prioritized? You know, that kind of stuff. Today, however, I&#8217;m going to write about a very different backlog, that is the static analysis defect [...]]]></description>
			<content:encoded><![CDATA[<p>As a product manager, the only backlog I typically care about is my <a href="http://www.mountaingoatsoftware.com/scrum/product-backlog">product backlog</a>. Do I have the right stories in there? Do the stories have enough detail? Are they properly prioritized? You know, that kind of stuff. Today, however, I&#8217;m going to write about a very different backlog, that is the <a href="http://codeintegrity.blogspot.com/2009/06/cost-of-static-analysis-backlogs.html">static analysis defect backlog</a>.</p>
<p>A static analysis backlog is created when you run a static analysis product on your code base for the very first time. Chances are pretty good that the first analysis is going to list a large number of defects, some that are without question real, and some that perhaps are not. Do not freak out! This is the first time that analysis engine has &#8216;laid eyes&#8217; upon your code and it is going to flex its muscles and show you any weaknesses it believes exist. So how does one deal with this? Here are a few strategies to help you:</p>
<p>1) Don&#8217;t <a href="http://www.urbandictionary.com/define.php?term=%22boiling%20the%20ocean%22">boil the ocean</a>. Before you even run that first analysis, don&#8217;t have a &#8220;wouldn&#8217;t it be cool&#8221; moment, where you decide to turn on every single rule the analysis engine has. There is a reason why static analysis tools haven&#8217;t turned on everything.  They are showing the most accurate and critical issues first.  So unless you have unlimited time and resources, your best bet is to start with a core set of rules and run the analysis based on that set. This core set of rules should include things such as memory/resource leaks, buffer overruns, null pointer dereferences, uninitialized variables, and so on. Add other rules once you have this core set under control.</p>
<div id="attachment_1237" class="wp-caption alignright" style="width: 310px"><a href="http://www.klocwork.com/blog/wp-content/uploads/2011/02/opossum.png"><img class="size-medium wp-image-1237" title="opossum" src="http://www.klocwork.com/blog/wp-content/uploads/2011/02/opossum-300x190.png" alt="" width="300" height="190" /></a><p class="wp-caption-text">Is your issue backlog making you cross eyed? Try these coping strategies.</p></div>
<p><br class="spacer_" /></p>
<p>2) Baseline your defects. Consider that first analysis your baseline and choose to &#8216;park&#8217; them for the time being. Chances are the product that the analysis was run on is one that has already been released to the public, and in good working order. Zero out these defects for now, and start to triage them, which leads into strategy #3.</p>
<p>3) This is going to sound pretty obvious, but when it comes to <a href="http://www.klocwork.com/products/documentation/current/Managing_your_issue_backlog_in_Klocwork_Review">managing your issue backlog</a> start looking at the most critical issues first. These are the ones that are most likely to cause a failure of some sort, so determine if these issues are real, and if so, fix them immediately. Once you&#8217;re done with the most critical issues, move to the next level of severity, and continue on that way.</p>
<p>4) Finally, tune your analysis. Any good vendor will allow you to tune your analysis. The benefits of tuning are twofold; 1) you can find code issues that would otherwise go undetected and, 2) reduce the number of issues that the engine reports incorrectly in the context of your source code. You should think of ways to give the tool more context about your code base to increase accuracy.</p>
<p>If you follow these suggestions, you&#8217;ll definitely have a better grasp of your bug backlog, and you&#8217;ll be able to execute on reducing that backlog quickly and efficiently. If you don&#8217;t, then at some point, you may feel a little like the critter pictured here.</p>
<p>If there are any other strategies you&#8217;ve tried to deal with your bug backlog, leave a comment or two. I&#8217;d love to hear about them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2011/02/dealing-with-a-different-type-of-backlog-your-bug-backlog/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Patterns of Bugs</title>
		<link>http://www.klocwork.com/blog/2011/01/patterns-of-bugs/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=patterns-of-bugs</link>
		<comments>http://www.klocwork.com/blog/2011/01/patterns-of-bugs/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 16:49:15 +0000</pubDate>
		<dc:creator>Brendan Harrison</dc:creator>
				<category><![CDATA[Coding Standards]]></category>
		<category><![CDATA[General Coding]]></category>
		<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[bug patterns]]></category>
		<category><![CDATA[coding standards]]></category>
		<category><![CDATA[Static Analysis]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=1214</guid>
		<description><![CDATA[Nice blog post from Walter Bright over at Dr. Dobbs on the Patterns of Bugs. He ties together bug patterns, recommended process changes, and the resulting productivity payoff from making these improvements. He recommends a bunch of process changes, including static analysis, code reviews, and coding standards, then goes on to review examples of different [...]]]></description>
			<content:encoded><![CDATA[<p>Nice blog post from Walter Bright over at Dr. Dobbs on the <a title="Patterns of Bugs Blog" href="http://www.drdobbs.com/blog/archives/2011/01/patterns_of_bug.html" target="_blank">Patterns of Bugs</a>. He ties together bug patterns, recommended process changes, and the resulting productivity payoff from making these improvements.   He recommends a bunch of process changes, including <a title="Static Analysis" href="http://www.klocwork.com/products/insight/klocwork-truepath" target="_blank">static analysis</a>, <a title="Peer Code Review" href="http://www.klocwork.com/solutions/code-review" target="_blank">code reviews</a>, and <a title="Coding Standards" href="http://www.klocwork.com/solutions/misra-coding-standards/" target="_blank">coding standards</a>, then goes on to review examples of different bug patterns. A few can be detected with static analysis (coding mistakes as written) but many are errors with the code as intended (something static analysis doesn’t check&#8230; that’s what testing is for). His main recommendation seems to be that bugs can often be pattern based, so once a bug is identified, take steps to remove that pattern from your code through process or tool changes.</p>
<p><a href="http://www.klocwork.com/blog/wp-content/uploads/2011/01/ladybug-03.jpg"><img class="alignright size-medium wp-image-1216" title="ladybug-03" src="http://www.klocwork.com/blog/wp-content/uploads/2011/01/ladybug-03-300x296.jpg" alt="Patterns of Bugs" width="300" height="296" /></a></p>
<p style="padding-left: 30px;"><em>Once the pattern is identified, then look for changes in process that will permanently eliminate that bug. Eliminate enough of the bug patterns, and you should enjoy a substantial increase in productivity. </em></p>
<p>His experience is that, over time this kind of systematic approach to fixing bugs makes developers better.</p>
<p style="padding-left: 30px;"><em> I&#8217;ve noticed in my decades of writing programs that I just don&#8217;t make the kinds of mistakes I used to. Apparently I&#8217;ve unconsciously evolved coping strategies to avoid them. Identifying and building such strategies into the process means everyone can benefit from that experience. </em></p>
<p>We certainly see that in the area of static analysis bug detection; lots of customers report that their developers make fewer mistakes, defect injection rates go down, and overall productivity is improved.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2011/01/patterns-of-bugs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PM Thoughts on Code Reviews</title>
		<link>http://www.klocwork.com/blog/2010/11/pm-thoughts-on-code-reviews/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=pm-thoughts-on-code-reviews</link>
		<comments>http://www.klocwork.com/blog/2010/11/pm-thoughts-on-code-reviews/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 18:07:59 +0000</pubDate>
		<dc:creator>Todd Landry</dc:creator>
				<category><![CDATA[Agile Development]]></category>
		<category><![CDATA[Code Review]]></category>
		<category><![CDATA[General Coding]]></category>
		<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[code reviews]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=1133</guid>
		<description><![CDATA[While I may not be the most active Twitter-er in the world, the one thing I have noticed is that there is an awful lot of activity around the term “code review” lately. Since code reviews have become a widely used practice, I thought I would share one of my experiences about code reviews with [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">While I may not be the most active Twitter-er in the world, the one thing I have noticed is that there is an awful lot of activity around the term “code review” lately. Since code reviews have become a widely used practice, I thought I would share one of my experiences about code reviews with you, from a product manager perspective.</p>
<p>In my first Agile team, many years ago, it was tabled (in our retrospective meeting after a couple of Sprints) that code reviews should be added to our definition of “<a href="http://www.scrumalliance.org/articles/105-what-is-definition-of-done-dod">Done</a>”.  Let’s just say my initial response was less than enthusiastic… but why was that?  Well, in my opinion (perhaps uneducated on this topic), doing code reviews seems to add more to the time it takes to finish stories, so that means less stories are getting done per iteration, which potentially means longer release times, or releases with less functionality than hoped for. This is not something a Product Manager is usually receptive to. After some debate, we put it to a vote where the “yays” defeated the “nays” by a fairly healthy margin (okay, it missed being unanimous by one vote).  So we updated our “Done” criteria and moved into our next Sprint.</p>
<p>Our next couple of sprints went off similar to our earlier sprints, I didn’t really notice any differences. We seemed to have about the same number of stories being started and completed, and I for one was mildly surprised that we were able to maintain the same velocity, even with the extra process of doing code reviews for each story. Curious, I decided to talk to one of the more senior developers about what was going on. He walked me over to our Scrum board and asked me if anything looked different. Nothing jumped out at me initially, until he pointed out that the number of ‘bug’ cards (the dreaded red cards) were significantly less than in those early iterations. He proceeded to tell me that the code reviews were playing a major role in this. Developers were finding things early and fixing them before passing the code onto the testers, leaving the testers to focus on testing the actual features …crazy, I know.<a href="http://www.klocwork.com/blog/wp-content/uploads/2010/11/DSC011661.jpg"><img class="alignright size-medium wp-image-1135" title="Scrum board" src="http://www.klocwork.com/blog/wp-content/uploads/2010/11/DSC011661-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>It really appeared as though the code reviews were producing better code, without actually slowing down the development process. My opinions of code reviews did a complete 180…now they were helping to contribute to better quality code that I could show our customers, without having to sacrifice anything in the way of release delays or velocity degradation. I had become a believer!</p>
<p> I think I have something to Twitter about now…</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2010/11/pm-thoughts-on-code-reviews/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multicore exposes more frog versus snake (deadlock) bugs</title>
		<link>http://www.klocwork.com/blog/2010/09/multicore-exposes-more-snake-versus-frog-bugs/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=multicore-exposes-more-snake-versus-frog-bugs</link>
		<comments>http://www.klocwork.com/blog/2010/09/multicore-exposes-more-snake-versus-frog-bugs/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 15:55:39 +0000</pubDate>
		<dc:creator>Eric Hollebone</dc:creator>
				<category><![CDATA[Embedded]]></category>
		<category><![CDATA[General Coding]]></category>
		<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[Software Complexity]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[deadlock]]></category>
		<category><![CDATA[embedded development]]></category>
		<category><![CDATA[multicore]]></category>
		<category><![CDATA[multithreading]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=1099</guid>
		<description><![CDATA[Continuing the discussion about the embedded community moving to muticore/hetrogeneous hardware from watch out here comes multicore, embedded software development teams have historically been shielded from mulitcore issues. This is due to the specialized functionality of many embedded application classes and the inherent serialized nature of the C language.[1] Muticore is an ambiguous term for software developers and one they [...]]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignright" style="width: 310px"><img title="Deadlock: frog vs. snake" src="http://www.klocwork.com/blog/wp-content/uploads/2010/09/Deadlock-frog-versus-snake.jpg" alt="" width="300" /><p class="wp-caption-text">Deadlock: frog vs. snake<br/>Photo: David Maitland / National Geographic</p></div>
<p>Continuing the discussion about the embedded community moving to muticore/hetrogeneous hardware from <a href="http://www.klocwork.com/blog/2010/09/embedded-developers-watch-out-here-comes-multicore/">watch out here comes multicore</a>, embedded software development teams have historically been shielded from mulitcore issues. This is due to the specialized functionality of many embedded application classes and the inherent serialized nature of the C language.<sup><a href="#vdc">[1]</a></sup></p>
<p>Muticore is an ambiguous term for software developers and one they don&#8217;t really use; software developers think in terms of threads/processes and concurrency, not how many cores or processors are available on the target. Concurrency is not a new topic either as Mark Smotherman captured in a <a href="http://www.cs.clemson.edu/~mark/multithreading.html">history of multithreading</a>, it has been a subject in computer science since its early beginnings in the 1950s.</p>
<p>What has changed is the rapidly increasing use of multicore technologies for embedded devices. One of the prominent software challenges that moving to multicore execution exposes is latent deadlocking bugs as true parallel execution comes into play, instead of a single core&#8217;s task scheduling/context switching techniques.</p>
<p>As an example, consider the following code snippet, which has been paraphrased from a deadlock discovered in a real-world open source multithreaded project.</p>
<p>Can you spot the deadlock?</p>
<pre><code>lock_t lock1, lock2;
int refCount = 0;

void enter() {
   reserve_lock(lock1);
      if( refCount == 0 )
         reserve_lock(lock2);
       release_lock(lock1);
   refCount++;
}

void leave() {
   reserve_lock(lock1);
   refCount--;
   if( refCount == 0 )
      release_lock(lock2);
   release_lock(lock1);
}</code></pre>
<p>To see the answer and understand the conditions that lead to the deadlock, download Klocwork&#8217;s whitepaper on <strong><a href="http://www.klocwork.com/resources/endian-deadlock-multicore-challenges/">Developing software for multicore</a></strong>.</p>
<p>A little about the picture in this post.  I found it when searching for pictures of deadlocks.  The photographer, David Maitland, titled his image &#8220;<a title="Deadlock: frog vs. snake" href="http://news.nationalgeographic.com/news/2008/10/photogalleries/best-animal-wildlife-photos/photo4.html" target="_blank">Deadlock</a>&#8221; and describes it as a continuing struggle between a Morelet&#8217;s tree frog and cat-eyed snake. After three hours in the high-stakes cage match, Maitland said there was no clear winner.</p>
<p><br class="spacer_" /></p>
<hr size="1" />
<p><a name="vdc">VDC Research</a>, “<a href="http://www.klocwork.com/resources/research/klocwork-research-vdc-multicore-software-challenges">Next Generation Embedded Hardware Architectures: Driving Onset of Project Delays, Costs Overruns, and Software Development Challenges</a>”, September 2010.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2010/09/multicore-exposes-more-snake-versus-frog-bugs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Google offers cash reward for finding bugs in Chrome</title>
		<link>http://www.klocwork.com/blog/2010/02/google-offers-cash-reward-for-finding-bugs-in-chrome/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=google-offers-cash-reward-for-finding-bugs-in-chrome</link>
		<comments>http://www.klocwork.com/blog/2010/02/google-offers-cash-reward-for-finding-bugs-in-chrome/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 20:23:58 +0000</pubDate>
		<dc:creator>Eric Hollebone</dc:creator>
				<category><![CDATA[General Coding]]></category>
		<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[Software Security]]></category>
		<category><![CDATA[google chrome]]></category>
		<category><![CDATA[software security]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=814</guid>
		<description><![CDATA[As Google Chrome climbs out of obscurity in the browser market and expands into a light-weight but fully functional OS, security seems to have become a top of mind issue over at chromium headquarters. In the Chromium Blog, Chris Evans of Chrome Security announced a cash for bugs initiative, paying between 500 and 1337 USD depending on the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.klocwork.com/blog/wp-content/uploads/2010/02/Google_Chrome_Browser_log_nobugs.png"><img class="alignleft size-full wp-image-816" title="Google Chrome Browser logo - no Bugs" src="http://www.klocwork.com/blog/wp-content/uploads/2010/02/Google_Chrome_Browser_log_nobugs.png" alt="Google Chrome no bugs" width="142" height="133" /></a>As Google Chrome climbs out of obscurity in the <a title="January 2010 Browser Market Share [according to netmarketshare]" href="http://www.netmarketshare.com/report.aspx?qprid=0&amp;qptimeframe=M&amp;qpsp=132&amp;qpcustomb=" target="_blank">browser market </a>and expands into a light-weight but<a title="Chromium OS" href="http://dev.chromium.org/chromium-os"> fully functional OS</a>, security seems to have become a top of mind issue over at chromium headquarters.</p>
<p>In the Chromium Blog, Chris Evans of Chrome Security announced a <a href="http://blog.chromium.org/2010/01/encouraging-more-chromium-security.html">cash for bugs initiative</a>, paying between 500 and <a title="10100111001 (Leet)" href="http://en.wikipedia.org/wiki/Leet">1337</a> USD depending on the severity for any previously undiscovered flaw.  I am glad to see Google encouraging the community at large to participate in hardening my current browser of choice.  As Chris points out, Mozilla was one of the first to embark on this type of program, but I am happy to see Chrome following suit.  Me and my online transactions appreciate it.</p>
<p>Hmm.  Maybe I should roll-up the sleeves and  invoke the  &#8221;<a title="“I’m gonna write me a new minivan” – is zero software bugs the right goal?" href="http://www.klocwork.com/blog/2009/10/im-gonna-write-me-a-new-minivan-is-zero-software-bugs-the-right-goal/" target="_self">I&#8217;m gonna write me a minivan</a>&#8221; approach and get the driveway cleared for the armored cash trucks.</p>
<p>But seriously, if you&#8217;re interested in helping out and getting a small reward for your efforts, visit the <a title="Chromium Vulnerability Contribution Program" href="http://dev.chromium.org/Home/chromium-security/Chromium_Vulnerability_Contribution_Program_.pdf?attredirects=0&amp;d=1" target="_blank">Chromium Security</a> project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2010/02/google-offers-cash-reward-for-finding-bugs-in-chrome/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Going Agile Part 4 &#8211; Iteration 1: The Good, The Bad, and the Ugly</title>
		<link>http://www.klocwork.com/blog/2010/01/going-agile-part-4-iteration-1-the-good-the-bad-and-the-ugly/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=going-agile-part-4-iteration-1-the-good-the-bad-and-the-ugly</link>
		<comments>http://www.klocwork.com/blog/2010/01/going-agile-part-4-iteration-1-the-good-the-bad-and-the-ugly/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 16:09:57 +0000</pubDate>
		<dc:creator>Todd Landry</dc:creator>
				<category><![CDATA[Agile Development]]></category>
		<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[communication]]></category>
		<category><![CDATA[scrum]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=689</guid>
		<description><![CDATA[I just couldn’t resist using the classic spaghetti Western as the title for this instalment of my Going Agile series because it a) it was an awesome movie, and b) it truly sums up that 1st iteration of ours. My last post was all about the 1st iteration planning meeting, and how it was such [...]]]></description>
			<content:encoded><![CDATA[<p>I just couldn’t resist using the classic spaghetti <a href="http://en.wikipedia.org/wiki/The_Good,_the_Bad_and_the_Ugly">Western </a>as the title for this instalment of my Going Agile series because it a) it was an awesome movie, and b) it truly sums up that 1<sup>st</sup> iteration of ours. My <a href="http://www.klocwork.com/blog/?p=672">last post </a>was all about the 1<sup>st</sup> iteration planning meeting, and how it was such an exciting and productive time for our team. We came out of that meeting a little weary, but extremely motivated to get to work. We were also just a tad naive.</p>
<p><a href="http://www.klocwork.com/blog/wp-content/uploads/2010/01/the-good-the-bad-and-the-ugly.jpg"><img class="alignleft size-medium wp-image-690" title="the-good-the-bad-and-the-ugly" src="http://www.klocwork.com/blog/wp-content/uploads/2010/01/the-good-the-bad-and-the-ugly-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>The next 2 weeks were a roller coaster as we cut our teeth with Scrum. First the good:</p>
<ul>
<li>Communication: the interaction amongst the team members was definitely improved. If someone needed an answer to something, they immediately sought out help. The team realized that if they didn’t get timely answers, tasks wouldn’t get done. They really didn’t want to say those dreaded 2 words, “nothing finished”, in the daily scrum meeting.</li>
<li>Meetings: The <a href="http://www.mountaingoatsoftware.com/scrum/daily-scrum">daily Scrum </a>meetings were kept short and  sweet as everyone said what tasks they had finished, what they were working on, and if there were any roadblocks in the way. If something required further discussion, a break out meeting with the appropriate people was held.</li>
<li>Energy: This was a high performing team to begin with, but there was now a newfound energy and buzz. This was a fun team to be around!</li>
</ul>
<p>As the title suggests, there certainly was some bad in that first iteration.</p>
<ul>
<li>Testing and documentation: These were the 2 areas that struggled the most in the first iteration (and the next couple as well). They felt that their work was too heavily back loaded, that is, they would receive their stuff too late in the iteration to either test or document properly. Many of the stories were not totally Done because they were either not tested properly or documented with the time they were given.</li>
<li>Defects and bugs: Because testing happened so late in the iteration, many of the bugs they found could not be addressed in that iteration. These bugs would have to be carried over to the next iteration, meaning the number of new stories would have to be reduced.</li>
</ul>
<p>Now for the ugly.</p>
<ul>
<li>After just a day or so into the iteration, a plethora of unplanned tasks starting showing up on the Scrum board for many of the stories. These stories now had many new hours of tasks added to them, and we fell behind very quickly. This leads into the next ugly&#8230;</li>
<li>The <a href="http://en.wikipedia.org/wiki/Burn_down_chart">Burndown</a> chart: Talk about a misnomer! We started to affectionately call our chart the burn-up chart, because there was very little down direction going on with it. Our chart would have looked great at a sales meeting, but in our Scrum meeting, not so much.</li>
</ul>
<p>So as you can see our 1<sup>st</sup> iteration had its share of warts, and in fact, the next couple did as well. But we didn’t get frustrated. We learned from our mistakes and changed/added things based on those mistakes. The <a href="http://www.infoq.com/news/2009/09/key-elements-agile-retrospective">Retrospective</a> meetings were incredibly useful because they made us all take a hard, honest look at what went well, and what didn’t. The next, and last entry in my Going Agile series will look at the Retrospective meeting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2010/01/going-agile-part-4-iteration-1-the-good-the-bad-and-the-ugly/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>From Static Analysis to 0day Exploit &#8211; a demonstration</title>
		<link>http://www.klocwork.com/blog/2009/12/from-static-analysis-to-0day-exploit-a-demonstration/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=from-static-analysis-to-0day-exploit-a-demonstration</link>
		<comments>http://www.klocwork.com/blog/2009/12/from-static-analysis-to-0day-exploit-a-demonstration/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 22:32:40 +0000</pubDate>
		<dc:creator>Eric Hollebone</dc:creator>
				<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[Software Quality]]></category>
		<category><![CDATA[Software Security]]></category>
		<category><![CDATA[Static Analysis]]></category>
		<category><![CDATA[0day exploit]]></category>
		<category><![CDATA[buffer overrun]]></category>
		<category><![CDATA[software security]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=528</guid>
		<description><![CDATA[I have always been fascinated by the whole area of code vulnerabilities and security exploits and how hackers turn those issues into real-world problems for the rest of us. Jeremy Brown posted an interesting article on Jeremy&#8217;s Computer Security blog where he uses his security know-how to draw a straight line between a software vulnerability found with [...]]]></description>
			<content:encoded><![CDATA[<p>I have always been fascinated by the whole area of code vulnerabilities and security exploits and how hackers turn those issues into real-world problems for the rest of us.</p>
<p>Jeremy Brown posted an interesting article on <a title="From Static Analysis to 0day Exploit" href="http://jbrownsec.blogspot.com/2009/12/from-static-analysis-to-0day-exploit.html" target="_blank">Jeremy&#8217;s Computer Security blog</a> where he uses his security know-how to draw a straight line between a software vulnerability found with <a href="http://www.klocwork.com/products/insight/klocwork-truepath/">static analysis</a> and a real <a href="http://en.wikipedia.org/wiki/0day">0day</a> exploit on an open source project called <a title="The Graphical Audio Language" href="http://galan.sourceforge.net/" target="_blank">gAlan</a>.</p>
<p>Jeremy takes us on a short journey where he finds an unprotected buffer with static analysis, creates an exploit payload to cause a buffer overrun, rewrites the instruction pointer and executes a telnet session, demonstrating how easy it is to turn a run of the mill application into a tunnel into the OS.</p>
<p>One of my colleagues did a similar <a title="Firefox vulnerability" href="http://www.klocwork.com/resources/on-demand-webinar/exploit-software-defect-firefox" target="_blank">presentation</a> like this a few years back with a Firefox vulnerability but this is a much better example! Very cool work Jeremy.</p>
<p>Enjoy&#8230;<br />
<object id="viddler" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="437" height="370" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="flashvars" value="fake=1" /><param name="src" value="http://www.viddler.com/player/2af2aaf3/" /><param name="name" value="viddler" /><param name="allowfullscreen" value="true" /><embed id="viddler" type="application/x-shockwave-flash" width="437" height="370" src="http://www.viddler.com/player/2af2aaf3/" name="viddler" flashvars="fake=1" allowfullscreen="true" allowscriptaccess="always"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2009/12/from-static-analysis-to-0day-exploit-a-demonstration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;I&#8217;m gonna write me a new minivan&#8221; &#8211; is zero software bugs the right goal?</title>
		<link>http://www.klocwork.com/blog/2009/10/im-gonna-write-me-a-new-minivan-is-zero-software-bugs-the-right-goal/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=im-gonna-write-me-a-new-minivan-is-zero-software-bugs-the-right-goal</link>
		<comments>http://www.klocwork.com/blog/2009/10/im-gonna-write-me-a-new-minivan-is-zero-software-bugs-the-right-goal/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 19:16:55 +0000</pubDate>
		<dc:creator>Eric Hollebone</dc:creator>
				<category><![CDATA[Agile Development]]></category>
		<category><![CDATA[General Industry]]></category>
		<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[bugs]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=473</guid>
		<description><![CDATA[I have always loved &#8220;I&#8217;m gonna write me a new minivan&#8221;  from Scott Adams.  To me, it never gets old.  Originally published in 1998, the theme that applied then still does today: driving 100% of defects or bugs out of the code-base is a laudable goal, but is it really the right one?   I would have to argue [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left; "><img class="alignnone size-full wp-image-478" title="dilbert-minivan-small" src="http://www.klocwork.com/blog/wp-content/uploads/2009/10/dilbert-minivan-small.png" alt="dilbert-minivan-small" width="450" height="147" /></p>
<p style="text-align: left; ">I have always loved &#8220;I&#8217;m gonna write me a new minivan&#8221;  from <a title="Dilbert.com" href="http://www.dilbert.com" target="_blank">Scott Adams</a>.  To me, it never gets old.  Originally published in 1998, the theme that applied then still does today: driving 100% of defects or bugs out of the code-base is a laudable goal, but is it really the right one?   I would have to argue no.  There&#8217;s no silver bullet out there that will find all software defects and solve issues automagically, and until there is, software development will continue to struggle with prioritization.  Unfortunately, we live in a world of finite resources and constantly evolving demands, but we can always dream about being Wally for a little while.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2009/10/im-gonna-write-me-a-new-minivan-is-zero-software-bugs-the-right-goal/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Top 5 Java quality bugs</title>
		<link>http://www.klocwork.com/blog/2009/10/top-5-java-quality-bugs/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=top-5-java-quality-bugs</link>
		<comments>http://www.klocwork.com/blog/2009/10/top-5-java-quality-bugs/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 14:58:33 +0000</pubDate>
		<dc:creator>Alen Zukich</dc:creator>
				<category><![CDATA[General Coding]]></category>
		<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[Software Quality]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[embedded development]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=451</guid>
		<description><![CDATA[In a previous posts I reviewed the Top 5 C/C++ and Top 5 C# quality bugs that I that I see time and time again looking at customer code. I wrote my Java Top 5 with an embedded programming focus and the folks at www.embedded.com decided to publish it on their site. Here’s a snippet [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous posts I reviewed the <a href="http://www.klocwork.com/blog/2009/07/top-5-cc-quality-bugs/" target="_blank">Top 5 C/C++</a> and <a href="http://www.klocwork.com/blog/2009/09/top-5-c-quality-bugs/" target="_blank">Top 5 C#</a> quality bugs that I that I see time and time again looking at customer code. I wrote my Java Top 5 with an embedded programming focus and the folks at <a href="http://www.embedded.com" target="_blank">www.embedded.com</a> decided to publish it on their site. Here’s a snippet below and the full Top 5 Java bugs article can be found <a title="Top 5 Java bugs" href="http://www.embedded.com/columns/guest/220300859" target="_blank">here</a>.</p>
<p style="padding-left: 30px;">While C dominates as the programming language of choice for embedded development, the use of Java is definitely on the rise. In fact, according to a recent VDC survey, 12.3% of respondents currently use Java in the embedded space, and 17.9% expect to be using Java in the next two years.</p>
<p style="padding-left: 30px;">For those transitioning from embedded development using C, you might find yourself falling into the hype that Java is a &#8220;safe&#8221; language. For example, Java developers face no requirement for managing memory associated with objects. However, this is where the trap may be laid. Even though there&#8217;s no need for memory management, developers may need to keep track of specific resources the object allocates. This is especially true in an embedded context where resources are often constrained. Even for experienced developers, these traps pop up time and again and can easily jeopardize your code quality and security.</p>
<p style="padding-left: 30px;">Here&#8217;s a round-up of the top five programming issues developers should be aware of in embedded Java development [<a href="http://www.embedded.com/columns/guest/220300859" target="_blank">More...</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2009/10/top-5-java-quality-bugs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Top 5 C# quality bugs</title>
		<link>http://www.klocwork.com/blog/2009/09/top-5-c-quality-bugs/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=top-5-c-quality-bugs</link>
		<comments>http://www.klocwork.com/blog/2009/09/top-5-c-quality-bugs/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 15:45:03 +0000</pubDate>
		<dc:creator>Alen Zukich</dc:creator>
				<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[Software Quality]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[quality bugs]]></category>
		<category><![CDATA[source code analysis]]></category>
		<category><![CDATA[Static Analysis]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=367</guid>
		<description><![CDATA[In a previous post I provided the top 5 C/C++ quality bugs that I that I see time and time again looking at customer code.  Time for the C# version: 1.    Null pointer exceptions from a method 1                  public class A { 2                      public A foo() { 3                          if (flag) 4                              return null; 5                          return [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous <a href="http://www.klocwork.com/blog/?p=221" target="_blank">post</a> I provided the top 5 C/C++ quality bugs that I that I see time and time again looking at customer code.  Time for the C# version:</p>
<p><strong>1.    Null pointer exceptions from a method</strong></p>
<pre><code>1                  public class A {
2                      public A foo() {
3                          if (flag)
4                              return null;
5                          return new A();
6                      }
7
8                      public void var() {
9                          A a = foo();
10                         if (flag)
11                             a.foo();
12                     }
13
14                     private int flag;
15                 }</code></pre>
<p>This is the most common issue I see.  In this example a warning is issued at line 11 for a possible null pointer exception.  Essentially there is a potential for a null value from the method foo().  I believe I see these issues more than any others  because of the inter-procedural context of this issue.  This example is quite simple, but where you can easily get lost is when that null value is coming from a long method call chain in multiple classes.</p>
<p><strong>2.    Resource leaks</strong></p>
<pre><code>1  using System;
2  using System.IO;
3
4  namespace LeakExample
5  {
6      class Test
7      {
8          public String Run(String name)
9          {
10             StreamReader reader = new StreamReader(name);
11             String result = reader.ReadToEnd();
12             reader.Close();
13             return result;
14         }
15     }
16 }</code></pre>
<p>I think for most of us this is pretty easy to see.   An object of &#8216;StreamReader&#8217; type is allocated and its reference is assigned to the &#8216;reader&#8217; member. If the call to &#8216;ReadToEnd&#8217; throws an exception, control is transferred out of method &#8216;Run&#8217;, variable &#8216;reader&#8217; goes out of scope, the object referenced by it becomes lost, but related resources are not disposed.  See my previous blog <a href="http://www.klocwork.com/blog/?p=36" target="_blank">post</a> on how some people miss this and what you need to do to fix this.</p>
<p><strong>3.    Forward null pointer exception</strong></p>
<pre><code>1                  public class A {
2                      public void foo() {
3                          A a = new A();
4                          if (a == 0)
5                              if (flag)
6                                  a.foo();
7                      }
8                      private int flag;
9                  }</code></pre>
<p>This is another example of a null pointer exception with a twist.  In this example the class data member ‘a’ is compared with 0 value at line 4, and therefore may still be expected to be null when it is dereferenced at line 6.</p>
<p><strong>4.    Reverse null pointer exception</strong></p>
<pre><code>1                  public class A {
2                      public void foo() {
3                          A a = null;
4                          a.foo();
5                          if (a == null)
6                              a = new A();
7                      }
8                  }</code></pre>
<p>Yes, another null pointer exception (getting a theme here?).  Same idea at #3 but in reverse order.  Here they dereference the data member ‘a’ at line 4 but later check for null at line 5.</p>
<p><strong>5.    Empty catch clause</strong></p>
<pre><code>1  class FileHandler {
2      public void Open(String name) {
3          try {
4              // opening file ...
5          } catch (FileNotFoundException e) {   // defect - no statements in the 'catch' clause
6          }
7      }
8  }</code></pre>
<p>Okay, so not exactly the big impact as the top 4, but I just had to mention it.  I’m always guaranteed to see some of these.  Granted they are maintainability issues more than anything else, but c’mon they are there for a purpose.<br />
As promised, I did say that I would post the Java version soon.  It is next&#8230;</p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" src="http://img.zemanta.com/pixy.gif?x-id=4d556a68-3448-8a97-810d-d0cc5d75f16f" alt="" /></div>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2009/09/top-5-c-quality-bugs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>That’s nice dear, how does it work?</title>
		<link>http://www.klocwork.com/blog/2009/08/that%e2%80%99s-nice-dear-how-does-it-work/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=that%25e2%2580%2599s-nice-dear-how-does-it-work</link>
		<comments>http://www.klocwork.com/blog/2009/08/that%e2%80%99s-nice-dear-how-does-it-work/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 14:52:58 +0000</pubDate>
		<dc:creator>Gwyn Fisher</dc:creator>
				<category><![CDATA[General Coding]]></category>
		<category><![CDATA[General Industry]]></category>
		<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[Software Quality]]></category>
		<category><![CDATA[Software Security]]></category>
		<category><![CDATA[Software Testing]]></category>
		<category><![CDATA[source code analysis]]></category>
		<category><![CDATA[Truepath]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=286</guid>
		<description><![CDATA[Ever been faced with that glassy-eyed expression, the look of unthinking, unwholesome fear when some long, incomprehensible word escapes your geeky mouth and upsets the maiden aunts around the once-a-year, wear-your-best-tie, try-not-to-die-before-the-cake’s-all-gone tea table? OK, so this paper won’t help you in that situation whatsoever, but if you replace your maiden aunts with a bunch [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_290" class="wp-caption alignleft" style="width: 130px"><a href="http://www.klocwork.com/resources/white-paper/truepath-scalable-whole-program-static-analysis"><img class="size-thumbnail wp-image-290" title="Klocwork Truepath whitepaper" src="http://www.klocwork.com/blog/wp-content/uploads/2009/08/klo_truepath_print-150x150.png" alt="TruPath whitepaper" width="120" height="120" /></a><p class="wp-caption-text">Truepath Analysis</p></div>
<p>Ever been faced with that glassy-eyed expression, the look of unthinking, unwholesome fear when some long, incomprehensible word escapes your geeky mouth and upsets the maiden aunts around the once-a-year, wear-your-best-tie, try-not-to-die-before-the-cake’s-all-gone tea table? OK, so this paper won’t help you in that situation whatsoever, but if you replace your maiden aunts with a bunch of your best geek friends, and replace the tea with a sturdy helping of Dew, knowing how a real whole program analysis solution works might just conceivably come in handy. Some day. “Dude, I was totally stoked when I read this thing, trust me it’s <em>ahh-some.</em>” Maybe.</p>
<p>Anyway, in the best traditions of self-serving corporate PR blogs everywhere, I give you… drum roll please… <a title="Whole Program Source Code Analysis" href="http://www.klocwork.com/resources/white-paper/truepath-scalable-whole-program-static-analysis" target="_blank">Whole Program Analysis, the Klocwork Way</a>.</p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2009/08/that%e2%80%99s-nice-dear-how-does-it-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Top 5 C/C++ quality bugs</title>
		<link>http://www.klocwork.com/blog/2009/07/top-5-cc-quality-bugs/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=top-5-cc-quality-bugs</link>
		<comments>http://www.klocwork.com/blog/2009/07/top-5-cc-quality-bugs/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 15:06:40 +0000</pubDate>
		<dc:creator>Alen Zukich</dc:creator>
				<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[Software Quality]]></category>
		<category><![CDATA[array index out of bounds]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[memory leaks]]></category>
		<category><![CDATA[null pointer dereference]]></category>
		<category><![CDATA[uninitialized variables]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=221</guid>
		<description><![CDATA[A recent article on the top five causes of poor software quality and top 5 non-technical mistakes inspired me to also provide a top five on software quality bugs.  Here is my top 5 list of bugs (with some simple examples) that I see time and time again looking at customer code: 1.    Null Pointer [...]]]></description>
			<content:encoded><![CDATA[<p>A recent <a href="http://itmanagement.earthweb.com/entdev/article.php/3827841/Top-Five-Causes-of-Poor-Software-Quality.htm" target="_blank">article</a> on the top five causes of poor software quality and top 5 non-technical <a href="http://www.makinggoodsoftware.com/2009/07/07/5-top-non-technical-mistakes-made-by-programmers/" target="_blank">mistakes</a> inspired me to also provide a top five on software quality bugs.  Here is my top 5 list of bugs (with some simple examples) that I see time and time again looking at customer code:</p>
<p>1.    Null Pointer dereference</p>
<p>This is far and beyond the most common issue that I see time and time again. </p>
<pre><code><span style="font-family: Courier New;">void npd_gen_must() {
int *p = 0; // NULL is assigned.
*p = 1;  // pointer is dereferenced
}</code></pre>
<p>Now this example is pretty basic and if you ever did something this obvious, maybe it was time to re-evaluate your development skills.  The idea is simple, you assign NULL somewhere then dereference it at some point later.  This is usually missed under a complicated control flow (many conditionals).  Or even more common is the fact that I see memory is allocated, but is never checked against NULL.  Now, some organizations don’t care about this but I would hope anyone doing embedded development is all over it.</p>
<p>2.    Null pointer dereference from function</p>
<p>This is really the same thing but with one very important difference.  This deals with issues from functions. </p>
<pre><code><span style="font-family: Courier New;">void xstrcpy(char *dst, char *src) {
if (!src) return;
 dst[0] = src[0];
}

char global;

char *xmalloc() {
  if (global) return &amp;amp;global;
  return 0;
}

void npd_func_might(int flag, char *arg) {
  char *p = &amp;amp;arg;
  if (flag) p = xmalloc(); // xmalloc() may return NULL
  if (arg) { p = arg; } // p may get a new value here
  xstrcpy(p, "Hello"); // p will be dereferenced in xstrcpy()
}</code></pre>
<p>It is this inter-procedural (spanning multiple files/functions) context that is often overlooked.</p>
<p>3.    Memory leaks</p>
<p>I have yet to find a programmer in the C/C++ world who doesn’t know this intimately.  Sadly they happen, a lot. </p>
<pre><code><span style="font-family: Courier New;">void foobar(int i) {
  char* p = new char[10];
  if(i) {
    p = 0;
  }
  delete[] p;
}</code></pre>
<p>Here we have dynamic memory stored in &#8216;p&#8217; and allocated through the function &#8216;new[]&#8216; at line 3 and is ultimately lost at line 5.</p>
<p>4.    Array index out of bounds</p>
<p>Again, most people know what these are but there are so many variations of this that they are always inevitable. </p>
<pre><code><span style="font-family: Courier New;">int main() {
  char fixed_buf[10];
  sprintf(fixed_buf,"Very long format string\n");
  return 0;
}</code></pre>
<p>The string is 24 characters so at line 4 the array index of &#8216;fixed_buf&#8217; may be out of bounds. </p>
<p>5.    Uninitialized variables</p>
<pre><code><span style="font-family: Courier New;">int foo(int t) {
  int x;
  if (t &amp;gt; 16) {
    x = 1;
  } else if (t &amp;gt; 8) {
    x = 2;
  }
  return x + 1;
}</code></pre>
<p>The value of variable &#8216;x&#8217; can be used at line 8, when it might be uninitialized.  I always found these surprising that these come up as they are pretty basic.  But I tend to only see these in complex control flow paths.  So the developer might check for these under normal conditions but forgot on some path.  Especially for legacy code this might not bite you until you change something later on.</p>
<p>So that’s it.  These examples are pretty simple and certainly not reflective of the real world (or at least I hope not).  Later I will post the same idea for Java code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2009/07/top-5-cc-quality-bugs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bugs and your Backlog</title>
		<link>http://www.klocwork.com/blog/2009/07/bugs-and-your-backlog/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=bugs-and-your-backlog</link>
		<comments>http://www.klocwork.com/blog/2009/07/bugs-and-your-backlog/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 17:28:44 +0000</pubDate>
		<dc:creator>Todd Landry</dc:creator>
				<category><![CDATA[Agile Development]]></category>
		<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[backlog]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[iteration]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=219</guid>
		<description><![CDATA[There was a recent blog on whether or not you should have bugs (that were not found during the most recent iteration) added to your product backlog, or kept in a separate bug backlog. Here at Klocwork we have a defect database that is closely monitored by Support, dev, PM, and so on&#8230;suffice it to [...]]]></description>
			<content:encoded><![CDATA[<p>There was a recent <a target="_blank" href="http://blog.mountaingoatsoftware.com/bugs-on-the-product-backlog">blog </a>on whether or not you should have bugs (that were not found during the most recent iteration) added to your product backlog, or kept in a separate bug backlog. Here at Klocwork we have a defect database that is closely monitored by Support, dev, PM, and so on&#8230;suffice it to say, it has a high degree of visibility within the organization and will probably never go away. Being an Agile company we also have a product backlog that is reviewed daily and prioritized regularly. Every two weeks (coinciding with our iteration planning) PM and Support get together to discuss the highest priority bugs, and to determine if those bugs should/need to be added to the backlog for the next iteration. A key piece to this process is using tools to maintain this backlog. The backlog tool, which also has an integration with our defect tracking system provides a tight correlation between the two, and a level of automation that makes life a little easier for everyone. Once added, these bugs are prioritized just as we do with all of the other features (stories) we have in the backlog. We also have weekly status meetings where the most recent bugs are discussed, once again to ensure they receive the proper attention. </p>
<p>Since we are in the bug-finding business, we take bugs very seriously and adding them to our backlog (and as a part of our iteration planning) helps ensure we address them quickly. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2009/07/bugs-and-your-backlog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resource Leaks in C#</title>
		<link>http://www.klocwork.com/blog/2009/02/resource-leaks-in-c/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=resource-leaks-in-c</link>
		<comments>http://www.klocwork.com/blog/2009/02/resource-leaks-in-c/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 15:13:57 +0000</pubDate>
		<dc:creator>Alen Zukich</dc:creator>
				<category><![CDATA[Nasty Bugs]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[resource leaks]]></category>
		<category><![CDATA[Static Analysis]]></category>

		<guid isPermaLink="false">http://www.klocwork.com/blog/?p=36</guid>
		<description><![CDATA[I’m picking up the theme of the CWE Top 25 today (see posts below for more detail on the list itself, or check out this blog posting for a more exhaustive description) as we run into what is described as CWE-404 all the time in managed code environments. Although most C/C++ developers recognize explicit resource [...]]]></description>
			<content:encoded><![CDATA[<p>I’m picking up the theme of the CWE Top 25 today (see posts below for more detail on the list itself, or check out this <a href="http://sharpertutorials.com/top-25-dangerous-coding-errors/" target="_blank">blog</a><a href="http://sharpertutorials.com/top-25-dangerous-coding-errors/" target="_blank"> posting</a> for a more exhaustive description) as we run into what is described as <a href="http://cwe.mitre.org/data/definitions/404.html" target="_blank">CWE-404</a> all the time in managed code environments.</p>
<p>Although most C/C++ developers recognize explicit resource management as an issue, I’ve recently found out talking to some of our customers that they are totally unaware of the need to worry about such things in Java and especially C#. I even had one customer tell me in the context of C# that the CLR will “take care” of the issue. While it’s perhaps true that eventually the Finalize() method might take care of many resources, professional developers really should take the utmost care in dealing with precious unmanaged resources like file handles, graphics handles, or database connections.</p>
<p>A simple but surprisingly common example in C# illustrates the point:<br />
<em><br />
using System;<br />
using System.IO;</em></p>
<p><em> </em></p>
<p><em>class Blah<br />
{<br />
static void Main()<br />
{<br />
StreamReader r = null;<br />
r = File.OpenText (“blah.txt”);<br />
if (r.EndOfStream) return;<br />
Console.WriteLine (r.ReadToEnd());<br />
}<br />
}</em></p>
<p>The StreamReader class used here encapsulates an unmanaged resource, the underlying file handle that the O/S allocates to the CLR during the call to OpenText(). As you can see, that unmanaged resource is never released back to the O/S (until such time as the application terminates, of course).</p>
<p>A simple statement:</p>
<p><em>r.Close();</em></p>
<p>in a finally block would clean it up.  Calling Close directly is okay but it is crucial to make sure you put that in the finally block.  The most common resource leaks that I see static analysis tools find are the ones where you see a developer has been smart enough to dispose of his resource but there is another path (such as an exception that can be thrown on a method) where the resource is not disposed.</p>
<p>Another easier way to dispose of the resource is to apply the “using” statement, which calls Dispose on an IDisposable object automatically for you. This code:</p>
<p><em>using (Streamreader r = File.OpenText (“blah.txt”))<br />
{<br />
…<br />
}</em></p>
<p>is the same as writing:</p>
<p><em>Streamreader r = File.OpenText (“blah.txt”);<br />
try<br />
{<br />
…<br />
}</em></p>
<p><em> finally<br />
{<br />
if (r != null)<br />
((IDisposable)r).Dispose();</em></p>
<p><em> }</em></p>
<p>So make sure you know that you need to dispose of certain resources.  In fairness, these can be hard issues to detect, particularly in an inter-procedural context, but good regimented use of code reviews, coupled with a good static analyzer should get you well on your way.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.klocwork.com/blog/2009/02/resource-leaks-in-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

