<?xml version='1.0' encoding='utf-8'?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:ns0="http://www.w3.org/2005/Atom" xmlns:ns1="http://purl.org/rss/1.0/modules/syndication/" xmlns:ns2="com-wordpress:feed-additions:1" xmlns:ns4="http://purl.org/rss/1.0/modules/content/" xmlns:ns5="http://wellformedweb.org/CommentAPI/" xmlns:ns6="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>c++ – Thameera's Blog</title>
	<ns0:link href="https://blog.thameera.com/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.thameera.com</link>
	<description />
	<lastBuildDate>Tue, 17 Sep 2013 18:24:38 +0000</lastBuildDate>
	<language>en-US</language>
	<ns1:updatePeriod>
	hourly	</ns1:updatePeriod>
	<ns1:updateFrequency>
	1	</ns1:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.12</generator>
<ns2:site>139676693</ns2:site>	<item>
		<title>Embarassing bugs in open source C/C++ projects</title>
		<link>https://blog.thameera.com/embarassing-bugs-in-open-source-cc-projects/</link>
					<comments>https://blog.thameera.com/embarassing-bugs-in-open-source-cc-projects/#comments</comments>
		
		<dc:creator>thameera</dc:creator>
		<pubDate>Tue, 17 Sep 2013 18:24:38 +0000</pubDate>
				<category>Uncategorized</category>
		<category>bugs</category>
		<category>c++</category>
		<category>chromium</category>
		<category>clang</category>
		<category>open-source</category>
		<category>winmerge</category>
		<guid isPermaLink="false">http://blog.thameera.com/?p=1166</guid>

					<description>Viva64 develops PVS-Studio, which is a static code analyzer for C/C++/C++11. But their popularity has come from the fact that they run this software on quite a few major open source projects around the internet and post the results. They hit the mark of 1000 error samples yesterday. Their bug database is a treasure trove.…&lt;p&gt;&lt;a class="more-link" href="https://blog.thameera.com/embarassing-bugs-in-open-source-cc-projects/" title="Continue reading ‘Embarassing bugs in open source C/C++ projects’"&gt;Continue reading &lt;span class="meta-nav"&gt;→&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;</description>
										<ns4:encoded>&lt;p&gt;&lt;a href="http://www.viva64.com/"&gt;Viva64&lt;/a&gt; develops &lt;a href="http://www.viva64.com/en/pvs-studio/"&gt;PVS-Studio&lt;/a&gt;, which is a static code analyzer for C/C++/C++11. But their popularity has come from the fact that they run this software on quite a few major open source projects around the internet and post the results. They hit the mark of &lt;a href="http://www.viva64.com/en/n/0098/"&gt;1000 error samples&lt;/a&gt; yesterday.&lt;/p&gt;
&lt;p&gt;Their &lt;a href="http://www.viva64.com/en/examples/"&gt;bug database&lt;/a&gt; is a treasure trove. For one they expose bugs in open source projects that may not be easily seen by the naked eye. And it’s a great learning resource to see common pitfalls.&lt;/p&gt;
&lt;p&gt;This bug from the Chromium project is obviously a hapless victim of copy-pasting:&lt;/p&gt;
&lt;pre class="brush: cpp; gutter: true; first-line: 1; highlight: []; html-script: false"&gt;
bool AutoFillProfileHasName(const AutoFillProfile&amp;amp; profile) {
  return
   !profile.GetFieldText(AutofillType(NAME_FIRST)).empty() ||
   !profile.GetFieldText(AutofillType(NAME_MIDDLE)).empty() ||
   !profile.GetFieldText(AutofillType(NAME_MIDDLE)).empty();
}
&lt;/pre&gt;
&lt;p&gt;Most probably the programmer intended to put &lt;code&gt;NAME_LAST&lt;/code&gt; at the end.&lt;/p&gt;
&lt;p&gt;Dereferencing a null pointer in Clang. Ouch.&lt;/p&gt;
&lt;pre class="brush: cpp; gutter: true; first-line: 1; highlight: []; html-script: false"&gt;
void MatcherGen::EmitLeafMatchCode(const TreePatternNode *N) {
  ...
  if (DI == 0) {
    errs() &amp;lt;&amp;lt; "Unknown leaf kind: " &amp;lt;&amp;lt; *DI &amp;lt;&amp;lt; "\n";
    abort();
  }
  ...
}
&lt;/pre&gt;
&lt;p&gt;And in this snippet from WinMerge, it might not be clear what the programmer has intended at first.&lt;/p&gt;
&lt;pre class="brush: cpp; gutter: true; first-line: 1; highlight: []; html-script: false"&gt;
void CDirView::GetItemFileNames(int sel,
  String&amp;amp; strLeft, String&amp;amp; strRight) const
{
  UINT_PTR diffpos = GetItemKey(sel);
  if (diffpos == (UINT_PTR)SPECIAL_ITEM_POS)
  {
    strLeft.empty();
    strRight.empty();
  }
  else
  {
     ...
  }
}
&lt;/pre&gt;
&lt;p&gt;It turns out that the intention was to clear the string. Actually it should’ve been &lt;code&gt;strLeft.clear();&lt;/code&gt; and &lt;code&gt;strRight.clear();&lt;/code&gt;. The static analyzer has caught the issue because the return value of &lt;code&gt;empty()&lt;/code&gt; is required to be utilized, which is not done here.&lt;/p&gt;
</ns4:encoded>
					
					<ns5:commentRss>https://blog.thameera.com/embarassing-bugs-in-open-source-cc-projects/feed/</ns5:commentRss>
			<ns6:comments>2</ns6:comments>
		
		
		<ns2:post-id>1166</ns2:post-id>	</item>
	</channel>
</rss>