<?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: Failing to Check Error Conditions Could Get You Sued</title>
	<atom:link href="http://www.veracode.com/blog/2009/03/failing-to-check-error-conditions-could-get-you-sued/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.veracode.com/blog/2009/03/failing-to-check-error-conditions-could-get-you-sued/</link>
	<description>Application security testing, analysis, and metrics</description>
	<lastBuildDate>Tue, 15 May 2012 22:16:53 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Chris Eng</title>
		<link>http://www.veracode.com/blog/2009/03/failing-to-check-error-conditions-could-get-you-sued/comment-page-1/#comment-2614</link>
		<dc:creator>Chris Eng</dc:creator>
		<pubDate>Mon, 30 Mar 2009 19:47:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.veracode.com/blog/?p=713#comment-2614</guid>
		<description>@ju ma: 

Yes, the idea was that lookup_payment_amount() is &quot;expected&quot; to return an amount, and that 0 indicates it was unable to do that, in which case calculate_payout_in_cents() returns -1.  I should have been clearer on that.

The unchecked error condition I was trying to highlight is in do_spin(), where the value of winnings is not checked.

Agree wholeheartedly that &#039;if (x=y())&#039; is a terrible construct, but unfortunately people use that shortcut all the time.</description>
		<content:encoded><![CDATA[<p>@ju ma: </p>
<p>Yes, the idea was that lookup_payment_amount() is &#8220;expected&#8221; to return an amount, and that 0 indicates it was unable to do that, in which case calculate_payout_in_cents() returns -1.  I should have been clearer on that.</p>
<p>The unchecked error condition I was trying to highlight is in do_spin(), where the value of winnings is not checked.</p>
<p>Agree wholeheartedly that &#8216;if (x=y())&#8217; is a terrible construct, but unfortunately people use that shortcut all the time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ju ma</title>
		<link>http://www.veracode.com/blog/2009/03/failing-to-check-error-conditions-could-get-you-sued/comment-page-1/#comment-2613</link>
		<dc:creator>ju ma</dc:creator>
		<pubDate>Mon, 30 Mar 2009 18:47:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.veracode.com/blog/?p=713#comment-2613</guid>
		<description>Not that one should ever intentionally write &#039;if (x = y)&#039; given that someone is likely to come along later and &#039;fix&#039; it to be &#039;if (x == y)&#039;; if you must write assignment in a subexpression, do the right thing (and what GCC, at least, will recognize as sign of intent) and parenthesize it; besides, don&#039;t use random integer values as booleans.  So it really should be &quot;if ((rv = lookup_payout_amount()) != 0)&quot;.  Of course, your example allows lookup_payment_amount to return -1 and have it not go through the error codepath, or -2 or whatever, so even if you eyeballed that and fixed the caller to check for &quot;-1&quot;, you&#039;d get screwed if -2 came up from somewhere else.  Also, if lookup_payment_amount is returning &#039;NULL&#039;, perhaps you should reconsider treating its return value as an integer.  And using pointers as booleans is even worse than using non-pointers as booleans.  So really it should be:

int *winamtp;

winamtp = lookup_payment_amount();
if (winamtp != NULL) {
  assert(*winamtp &gt;= 0);
  return *winamtp;
}
return (-1);</description>
		<content:encoded><![CDATA[<p>Not that one should ever intentionally write &#8216;if (x = y)&#8217; given that someone is likely to come along later and &#8216;fix&#8217; it to be &#8216;if (x == y)&#8217;; if you must write assignment in a subexpression, do the right thing (and what GCC, at least, will recognize as sign of intent) and parenthesize it; besides, don&#8217;t use random integer values as booleans.  So it really should be &#8220;if ((rv = lookup_payout_amount()) != 0)&#8221;.  Of course, your example allows lookup_payment_amount to return -1 and have it not go through the error codepath, or -2 or whatever, so even if you eyeballed that and fixed the caller to check for &#8220;-1&#8243;, you&#8217;d get screwed if -2 came up from somewhere else.  Also, if lookup_payment_amount is returning &#8216;NULL&#8217;, perhaps you should reconsider treating its return value as an integer.  And using pointers as booleans is even worse than using non-pointers as booleans.  So really it should be:</p>
<p>int *winamtp;</p>
<p>winamtp = lookup_payment_amount();<br />
if (winamtp != NULL) {<br />
  assert(*winamtp &gt;= 0);<br />
  return *winamtp;<br />
}<br />
return (-1);</p>
]]></content:encoded>
	</item>
</channel>
</rss>

