<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
<channel>
	<title>Comments for COdE fr3@K</title>
	
	<link>http://fsfoundry.org/codefreak</link>
	<description>Weblog of a lively geek.</description>
	<lastBuildDate>Thu, 04 Mar 2010 10:35:11 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/commentsforcodefreak" /><feedburner:info uri="commentsforcodefreak" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:browserFriendly></feedburner:browserFriendly><item>
		<title>Comment on 當 Constructor 遇上 Virtual Function by jeffhung</title>
		<link>http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/comment-page-1/#comment-12003</link>
		<dc:creator>jeffhung</dc:creator>
		<pubDate>Thu, 04 Mar 2010 10:35:11 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/?p=789#comment-12003</guid>
		<description>我習慣用 proxy (handle) class 包裝 class hierarchy 來解這個問題。因為 client code 只能接觸到 proxy (handle)，所以可以隔絕採用 &lt;a href="http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Virtual_Constructor" title="Virtual Constructor Idiom" rel="nofollow"&gt;Virtual Constructor Idiom&lt;/a&gt; 的 (醜陋) implementation class hierarchy。另外，proxy (handle) class 視情況，可以用 &lt;code&gt;shared_ptr&lt;FooImplBase&gt;&lt;/code&gt; 來盛裝 implementation object，以兼顧 thread-safety。

最後，&lt;a href="http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Base-from-Member" title="Base-from-Member Idiom" rel="nofollow"&gt;Base-from-Member Idiom&lt;/a&gt; 是這個問題的另外一種變形，稍加修改設計，亦可適用。</description>
		<content:encoded><![CDATA[<p>我習慣用 proxy (handle) class 包裝 class hierarchy 來解這個問題。因為 client code 只能接觸到 proxy (handle)，所以可以隔絕採用 <a href="http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Virtual_Constructor" title="Virtual Constructor Idiom" rel="nofollow">Virtual Constructor Idiom</a> 的 (醜陋) implementation class hierarchy。另外，proxy (handle) class 視情況，可以用 <code>shared_ptr&lt;FooImplBase&gt;</code> 來盛裝 implementation object，以兼顧 thread-safety。</p>
<p>最後，<a href="http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Base-from-Member" title="Base-from-Member Idiom" rel="nofollow">Base-from-Member Idiom</a> 是這個問題的另外一種變形，稍加修改設計，亦可適用。</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Quiz on C++ Object Model by Keiko</title>
		<link>http://fsfoundry.org/codefreak/2010/03/04/quiz-on-cpp-object-model/comment-page-1/#comment-11986</link>
		<dc:creator>Keiko</dc:creator>
		<pubDate>Thu, 04 Mar 2010 05:46:28 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/?p=878#comment-11986</guid>
		<description>不考慮 compiler 怎麼 encode type name 。印出：Base 再印出 Derived 。

因為&lt;a href="http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/" rel="nofollow"&gt;當 Constructor 遇上 Virtual Function&lt;/a&gt;說：
建構一個 Derived 的 object instance 時, 先被建構的是其父類別，因此此時 typeid 會是拿到 Base class 。待子類別建構完成後、在 main() 中的 d.print_type_name(); 呼叫才會拿到 Derived 。</description>
		<content:encoded><![CDATA[<p>不考慮 compiler 怎麼 encode type name 。印出：Base 再印出 Derived 。</p>
<p>因為<a href="http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/" rel="nofollow">當 Constructor 遇上 Virtual Function</a>說：<br />
建構一個 Derived 的 object instance 時, 先被建構的是其父類別，因此此時 typeid 會是拿到 Base class 。待子類別建構完成後、在 main() 中的 d.print_type_name(); 呼叫才會拿到 Derived 。</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on 當 Constructor 遇上 Virtual Function by Ricky Lung</title>
		<link>http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/comment-page-1/#comment-11924</link>
		<dc:creator>Ricky Lung</dc:creator>
		<pubDate>Wed, 03 Mar 2010 02:12:29 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/?p=789#comment-11924</guid>
		<description>好文章. 期待 "當 Destructor 遇上 Virtual + Multi-thread"</description>
		<content:encoded><![CDATA[<p>好文章. 期待 &#8220;當 Destructor 遇上 Virtual + Multi-thread&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on 當 Constructor 遇上 Virtual Function by Keiko</title>
		<link>http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/comment-page-1/#comment-11923</link>
		<dc:creator>Keiko</dc:creator>
		<pubDate>Wed, 03 Mar 2010 02:00:37 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/?p=789#comment-11923</guid>
		<description>可能是這裡：&lt;a href="http://tlsj.tenlong.com.tw/WebModule/BookSearch/bookSearchViewAction.do?isbn=0321334876&amp;sid=26943" rel="nofollow"&gt;Effective C++, 3rd&lt;/a&gt;: Item 9: Never call virtual functions during construction or destruction.</description>
		<content:encoded><![CDATA[<p>可能是這裡：<a href="http://tlsj.tenlong.com.tw/WebModule/BookSearch/bookSearchViewAction.do?isbn=0321334876&amp;sid=26943" rel="nofollow">Effective C++, 3rd</a>: Item 9: Never call virtual functions during construction or destruction.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on 當 Constructor 遇上 Virtual Function by av</title>
		<link>http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/comment-page-1/#comment-11895</link>
		<dc:creator>av</dc:creator>
		<pubDate>Tue, 02 Mar 2010 17:37:55 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/?p=789#comment-11895</guid>
		<description>我忘了之前在哪本書看過的，反正結論說，就是不要在 constructor 使用 virtual function 就對了。</description>
		<content:encoded><![CDATA[<p>我忘了之前在哪本書看過的，反正結論說，就是不要在 constructor 使用 virtual function 就對了。</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on StatCounter – Now 5 Times Better by fr3@K</title>
		<link>http://fsfoundry.org/codefreak/2007/05/30/statcounter-now-5-times-better/comment-page-1/#comment-11161</link>
		<dc:creator>fr3@K</dc:creator>
		<pubDate>Thu, 04 Feb 2010 05:41:47 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2007/05/30/statcounter-now-5-times-better/#comment-11161</guid>
		<description>500 page view log entries.</description>
		<content:encoded><![CDATA[<p>500 page view log entries.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on StatCounter – Now 5 Times Better by bao</title>
		<link>http://fsfoundry.org/codefreak/2007/05/30/statcounter-now-5-times-better/comment-page-1/#comment-11160</link>
		<dc:creator>bao</dc:creator>
		<pubDate>Thu, 04 Feb 2010 03:06:47 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2007/05/30/statcounter-now-5-times-better/#comment-11160</guid>
		<description>But what's the log size mean?500 vistors?500K?500B?</description>
		<content:encoded><![CDATA[<p>But what&#8217;s the log size mean?500 vistors?500K?500B?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on 啟始 Global Variable 的困境 by jeffhung</title>
		<link>http://fsfoundry.org/codefreak/2008/12/29/issues-regarding-global-variable-initialization/comment-page-1/#comment-10754</link>
		<dc:creator>jeffhung</dc:creator>
		<pubDate>Thu, 07 Jan 2010 08:21:04 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2008/12/29/issues-regarding-global-variable-initialization/#comment-10754</guid>
		<description>「在 include 使用者自訂 header 之前 include 標準 header 是不好的習慣.」

我亦認同且自己嚴格執行這個 convention，不過，考慮到 pre-compiled header 可以有十分顯著的 compilation speed up 時，把 standard headers 放前面有其好處。</description>
		<content:encoded><![CDATA[<p>「在 include 使用者自訂 header 之前 include 標準 header 是不好的習慣.」</p>
<p>我亦認同且自己嚴格執行這個 convention，不過，考慮到 pre-compiled header 可以有十分顯著的 compilation speed up 時，把 standard headers 放前面有其好處。</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on What Should We Teach New Software Developers? Why? by fr3@K</title>
		<link>http://fsfoundry.org/codefreak/2010/01/05/what-should-we-teach-new-software-developers-why/comment-page-1/#comment-10728</link>
		<dc:creator>fr3@K</dc:creator>
		<pubDate>Tue, 05 Jan 2010 08:20:15 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/?p=791#comment-10728</guid>
		<description>沒有行醫經驗的特定專門醫學老師肯定是需要的, 但讓沒實務經驗的老師來教外科手術就很恐怖了吧.</description>
		<content:encoded><![CDATA[<p>沒有行醫經驗的特定專門醫學老師肯定是需要的, 但讓沒實務經驗的老師來教外科手術就很恐怖了吧.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on What Should We Teach New Software Developers? Why? by Jerry Wu</title>
		<link>http://fsfoundry.org/codefreak/2010/01/05/what-should-we-teach-new-software-developers-why/comment-page-1/#comment-10725</link>
		<dc:creator>Jerry Wu</dc:creator>
		<pubDate>Tue, 05 Jan 2010 03:08:33 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/?p=791#comment-10725</guid>
		<description>在醫學院裡面也是有專做基礎醫學的老師吧。個人認為學問跟技藝的確是要相輔相成，不過單就這段quote看起來好像是說那些不是"mastery of its app in complete systems"的人，不應該當老師?</description>
		<content:encoded><![CDATA[<p>在醫學院裡面也是有專做基礎醫學的老師吧。個人認為學問跟技藝的確是要相輔相成，不過單就這段quote看起來好像是說那些不是&#8221;mastery of its app in complete systems&#8221;的人，不應該當老師?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on 一看就知道 – 不 Thread-Safe 的 API by fr3@K</title>
		<link>http://fsfoundry.org/codefreak/2009/12/01/identifying-api-without-thread-safety/comment-page-1/#comment-10353</link>
		<dc:creator>fr3@K</dc:creator>
		<pubDate>Fri, 04 Dec 2009 02:06:15 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/?p=700#comment-10353</guid>
		<description>@av,

jeff 的意思是說 MS 提供的 runtime library 常會做非標準的事情. 例如 inet_ntoa 的回傳字串的實作.
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://linux.die.net/man/3/inet_ntoa" rel="nofollow"&gt;POSIX&lt;/a&gt; (BSD)&lt;/li&gt;
&lt;blockquote&gt;... The string is returned in a statically allocated buffer, which subsequent calls will overwrite.&lt;/blockquote&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms738564(VS.85).aspx" rel="nofollow"&gt;WIN32&lt;/a&gt;&lt;/li&gt;
&lt;blockquote&gt;... The string returned is guaranteed to be valid only until the next Windows Sockets function call is made within the same thread.&lt;/blockquote&gt;
&lt;/ul&gt;

於是, 在 windows 上的 programmer 並不會知道程式寫錯了, 那些問題也只會在程式要從 windows 跨到其他 platform 時爆炸.</description>
		<content:encoded><![CDATA[<p>@av,</p>
<p>jeff 的意思是說 MS 提供的 runtime library 常會做非標準的事情. 例如 inet_ntoa 的回傳字串的實作.</p>
<ul>
<li><a href="http://linux.die.net/man/3/inet_ntoa" rel="nofollow">POSIX</a> (BSD)</li>
<blockquote><p>&#8230; The string is returned in a statically allocated buffer, which subsequent calls will overwrite.</p></blockquote>
<li><a href="http://msdn.microsoft.com/en-us/library/ms738564(VS.85).aspx" rel="nofollow">WIN32</a></li>
<blockquote><p>&#8230; The string returned is guaranteed to be valid only until the next Windows Sockets function call is made within the same thread.</p></blockquote>
</ul>
<p>於是, 在 windows 上的 programmer 並不會知道程式寫錯了, 那些問題也只會在程式要從 windows 跨到其他 platform 時爆炸.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on 一看就知道 – 不 Thread-Safe 的 API by av</title>
		<link>http://fsfoundry.org/codefreak/2009/12/01/identifying-api-without-thread-safety/comment-page-1/#comment-10351</link>
		<dc:creator>av</dc:creator>
		<pubDate>Thu, 03 Dec 2009 17:46:55 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/?p=700#comment-10351</guid>
		<description>boost 的 thread_specific_ptr 應該就派的上用場了，不過我沒用過，不敢肯定。</description>
		<content:encoded><![CDATA[<p>boost 的 thread_specific_ptr 應該就派的上用場了，不過我沒用過，不敢肯定。</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on 一看就知道 – 不 Thread-Safe 的 API by jeffhung</title>
		<link>http://fsfoundry.org/codefreak/2009/12/01/identifying-api-without-thread-safety/comment-page-1/#comment-10342</link>
		<dc:creator>jeffhung</dc:creator>
		<pubDate>Tue, 01 Dec 2009 06:41:16 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/?p=700#comment-10342</guid>
		<description>Visual Studio 的骯髒解法是，針對這種 API，就 per thread 建立一個 buffer，指標存在 TLS (thread local storage) 裡，然後回傳之。

於是 upgrade visual studio 版本後，或是一開始就發現，程式很神奇的不會爛掉，但是當 porting 到其它「正常」的平台後，就爛掉了。</description>
		<content:encoded><![CDATA[<p>Visual Studio 的骯髒解法是，針對這種 API，就 per thread 建立一個 buffer，指標存在 TLS (thread local storage) 裡，然後回傳之。</p>
<p>於是 upgrade visual studio 版本後，或是一開始就發現，程式很神奇的不會爛掉，但是當 porting 到其它「正常」的平台後，就爛掉了。</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on So, You Think C++ is Slower than C by Royce</title>
		<link>http://fsfoundry.org/codefreak/2009/11/06/so-you-think-cpp-is-slower-than-c/comment-page-1/#comment-10276</link>
		<dc:creator>Royce</dc:creator>
		<pubDate>Mon, 09 Nov 2009 04:06:35 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/?p=631#comment-10276</guid>
		<description>I can't agree with you more.</description>
		<content:encoded><![CDATA[<p>I can&#8217;t agree with you more.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Security Enhanced CRT, Safer Than Standard Library? by Bill Spitzak</title>
		<link>http://fsfoundry.org/codefreak/2008/09/15/security-crt-safer-than-standard-library/comment-page-1/#comment-9804</link>
		<dc:creator>Bill Spitzak</dc:creator>
		<pubDate>Sat, 26 Sep 2009 21:31:15 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2008/09/15/security-crt-a-false-sense-of-security/#comment-9804</guid>
		<description>&lt;i&gt;It would be quite a stupid strategy to spend time and money trying to get these ‘*_s’ routines standardised if ‘lock in’ were Microsoft’s goal.&lt;/i&gt;

No, it is a brilliant strategy, because it allows you to make claims like this in order to try to defend their actions. It has zero effect on the "lock in" (the funcitons are trivial enough that no "standard" is needed to reverse-engineer them) but it provides a nice-sounding excuse for their compiler to spew warnings about portable code.</description>
		<content:encoded><![CDATA[<p><i>It would be quite a stupid strategy to spend time and money trying to get these ‘*_s’ routines standardised if ‘lock in’ were Microsoft’s goal.</i></p>
<p>No, it is a brilliant strategy, because it allows you to make claims like this in order to try to defend their actions. It has zero effect on the &#8220;lock in&#8221; (the funcitons are trivial enough that no &#8220;standard&#8221; is needed to reverse-engineer them) but it provides a nice-sounding excuse for their compiler to spew warnings about portable code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Security Enhanced CRT, Safer Than Standard Library? by Bill Spitzak</title>
		<link>http://fsfoundry.org/codefreak/2008/09/15/security-crt-safer-than-standard-library/comment-page-1/#comment-9803</link>
		<dc:creator>Bill Spitzak</dc:creator>
		<pubDate>Sat, 26 Sep 2009 21:24:09 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2008/09/15/security-crt-a-false-sense-of-security/#comment-9803</guid>
		<description>Just want to point out to mr tinfoil that strlcpy &lt;i&gt;does&lt;/i&gt; indicate if truncation happened, by returning a value larger than the value passed to it. This value is actually useful in that it is the size the buffer must be reallocated to.</description>
		<content:encoded><![CDATA[<p>Just want to point out to mr tinfoil that strlcpy <i>does</i> indicate if truncation happened, by returning a value larger than the value passed to it. This value is actually useful in that it is the size the buffer must be reallocated to.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Boost.Lexical-Cast Alternatives by fr3@K</title>
		<link>http://fsfoundry.org/codefreak/2009/09/17/boost-lexical-cast-alternatives/comment-page-1/#comment-9717</link>
		<dc:creator>fr3@K</dc:creator>
		<pubDate>Tue, 22 Sep 2009 02:45:59 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/?p=544#comment-9717</guid>
		<description>Works with lexi_cast4 :) Have fun~</description>
		<content:encoded><![CDATA[<p>Works with lexi_cast4 <img src='http://fsfoundry.org/codefreak/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Have fun~</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Boost.Lexical-Cast Alternatives by jeffhung</title>
		<link>http://fsfoundry.org/codefreak/2009/09/17/boost-lexical-cast-alternatives/comment-page-1/#comment-9641</link>
		<dc:creator>jeffhung</dc:creator>
		<pubDate>Mon, 21 Sep 2009 15:29:41 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/?p=544#comment-9641</guid>
		<description>The lexi_cast3() failed to compile for my simple test case:

&lt;code&gt;CHECK(lexi_cast3&lt;string&gt;(123) == "123");&lt;/code&gt;

(&lt;code&gt;CHECK()&lt;/code&gt; is a macro of my tiny test framework.)</description>
		<content:encoded><![CDATA[<p>The lexi_cast3() failed to compile for my simple test case:</p>
<p><code>CHECK(lexi_cast3&lt;string&gt;(123) == "123");</code></p>
<p>(<code>CHECK()</code> is a macro of my tiny test framework.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Security Enhanced CRT, Safer Than Standard Library? by Tinfoil</title>
		<link>http://fsfoundry.org/codefreak/2008/09/15/security-crt-safer-than-standard-library/comment-page-1/#comment-9141</link>
		<dc:creator>Tinfoil</dc:creator>
		<pubDate>Mon, 24 Aug 2009 13:19:45 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2008/09/15/security-crt-a-false-sense-of-security/#comment-9141</guid>
		<description>Hi fre3@K,

I still think the claim of a Microsoft conspiracy to 'lock in' developers cannot be taken seriously, except by those who could easily be convinced to wear tinfoil on their heads. It would be quite a stupid strategy to spend time and money trying to get these '*_s' routines standardised if 'lock in' were Microsoft's goal.

Second, the issue is not whether a routine is inherently 'unsafe' -- virtually anything /can/ be used 'safely' -- but whether an interface is so poorly designed that it promotes 'unsafe' coding. That is, it cannot be used 'safely' without a lot of extra code to check things that the library routine itself could (and should) very easily check.

Even the original strcpy can be used perfectly safely if developers keep track of string lengths and buffer sizes. The reason strcpy is 'unsafe' is because (a) the interface does not make it clear that developers /have to/ think about these things themselves, and (b) the compiler/runtime does not offer any checking or error reporting, so developers have to rely on spotting bugs in code reviews, with debug allocators (for heap buffers) or from crash dumps.

The main point of these '*_s' routines (well, my guess as to the point) is to force developers to think about string lengths, buffer sizes and truncation whenever they call one of the library routines, and to help them spot cases where they have made mistakes. If you don't know the string lengths, buffer sizes and whether or not you want to truncate, then your code is already wrong. If you do, then switching to these '*_s' routines is trivial. These are not marketing effects. Thinking about these things is exactly what every developer using the C library should do. Unfortunately, many of them don't, and even the ones that do sometimes make mistakes, for which the standard C library interfaces/runtime offer no help.

On the whole, strcpy is an awful design and strncpy makes things worse, by introducing confusing special cases without even guaranteeing null termination. strlcpy is a good (but non-standard) solution, and so is strcpy_s. Where strcpy_s wins is in requiring that developers who want truncation explicitly say so, in its more powerful error-handling mechanisms and in the overall consistency of the '*_s' interfaces.</description>
		<content:encoded><![CDATA[<p>Hi fre3@K,</p>
<p>I still think the claim of a Microsoft conspiracy to &#8216;lock in&#8217; developers cannot be taken seriously, except by those who could easily be convinced to wear tinfoil on their heads. It would be quite a stupid strategy to spend time and money trying to get these &#8216;*_s&#8217; routines standardised if &#8216;lock in&#8217; were Microsoft&#8217;s goal.</p>
<p>Second, the issue is not whether a routine is inherently &#8216;unsafe&#8217; &#8212; virtually anything /can/ be used &#8217;safely&#8217; &#8212; but whether an interface is so poorly designed that it promotes &#8216;unsafe&#8217; coding. That is, it cannot be used &#8217;safely&#8217; without a lot of extra code to check things that the library routine itself could (and should) very easily check.</p>
<p>Even the original strcpy can be used perfectly safely if developers keep track of string lengths and buffer sizes. The reason strcpy is &#8216;unsafe&#8217; is because (a) the interface does not make it clear that developers /have to/ think about these things themselves, and (b) the compiler/runtime does not offer any checking or error reporting, so developers have to rely on spotting bugs in code reviews, with debug allocators (for heap buffers) or from crash dumps.</p>
<p>The main point of these &#8216;*_s&#8217; routines (well, my guess as to the point) is to force developers to think about string lengths, buffer sizes and truncation whenever they call one of the library routines, and to help them spot cases where they have made mistakes. If you don&#8217;t know the string lengths, buffer sizes and whether or not you want to truncate, then your code is already wrong. If you do, then switching to these &#8216;*_s&#8217; routines is trivial. These are not marketing effects. Thinking about these things is exactly what every developer using the C library should do. Unfortunately, many of them don&#8217;t, and even the ones that do sometimes make mistakes, for which the standard C library interfaces/runtime offer no help.</p>
<p>On the whole, strcpy is an awful design and strncpy makes things worse, by introducing confusing special cases without even guaranteeing null termination. strlcpy is a good (but non-standard) solution, and so is strcpy_s. Where strcpy_s wins is in requiring that developers who want truncation explicitly say so, in its more powerful error-handling mechanisms and in the overall consistency of the &#8216;*_s&#8217; interfaces.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Security Enhanced CRT, Safer Than Standard Library? by fr3@K</title>
		<link>http://fsfoundry.org/codefreak/2008/09/15/security-crt-safer-than-standard-library/comment-page-1/#comment-9139</link>
		<dc:creator>fr3@K</dc:creator>
		<pubDate>Mon, 24 Aug 2009 10:53:36 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2008/09/15/security-crt-a-false-sense-of-security/#comment-9139</guid>
		<description>Hi Tinfoil,

First of all, let me just say that I am glad that you stopped calling people "tinfoil heads" in your response to Spitzak's comment.

The scenario you laid out does demonstrate your points very well, (BTW, I fixed the '\0' thing in your comment) but still, it doesn't mean one can't code securely using &lt;code&gt;strncpy&lt;/code&gt;.

This post is NOT about how I hated a set of (supposedly) more secured string functions that is not in the Standard, but rather, to dispute one compiler vendor's secure programming strategy, which IMO, produces more marketing effects than secure coding minds.

Apology to all if I've been misleading. By implying &lt;code&gt;strncpy&lt;/code&gt; is as safe as &lt;code&gt;strcpy_s&lt;/code&gt;, I meant one can't overrun destination buffers, as a result of invocations of either &lt;code&gt;strncpy&lt;/code&gt; or &lt;code&gt;strcpy_s&lt;/code&gt;, when used correctly. And one could indeed code securely, with &lt;code&gt;strncpy&lt;/code&gt;. (though additional effort may be required) As the zero filling behavior of &lt;code&gt;strncpy&lt;/code&gt;, which wastes CPU cycles, is another topic.</description>
		<content:encoded><![CDATA[<p>Hi Tinfoil,</p>
<p>First of all, let me just say that I am glad that you stopped calling people &#8220;tinfoil heads&#8221; in your response to Spitzak&#8217;s comment.</p>
<p>The scenario you laid out does demonstrate your points very well, (BTW, I fixed the &#8216;&#92;0&#8242; thing in your comment) but still, it doesn&#8217;t mean one can&#8217;t code securely using <code>strncpy</code>.</p>
<p>This post is NOT about how I hated a set of (supposedly) more secured string functions that is not in the Standard, but rather, to dispute one compiler vendor&#8217;s secure programming strategy, which IMO, produces more marketing effects than secure coding minds.</p>
<p>Apology to all if I&#8217;ve been misleading. By implying <code>strncpy</code> is as safe as <code>strcpy_s</code>, I meant one can&#8217;t overrun destination buffers, as a result of invocations of either <code>strncpy</code> or <code>strcpy_s</code>, when used correctly. And one could indeed code securely, with <code>strncpy</code>. (though additional effort may be required) As the zero filling behavior of <code>strncpy</code>, which wastes CPU cycles, is another topic.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
