<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Good News! strlen isn’t a banned API after all.</title><link>http://blogs.msdn.com/larryosterman/archive/2009/06/23/good-news-strlen-isn-t-a-banned-api-after-all.aspx</link><description>We were doing some code reviews on the new Win7 SDK samples the other day and one of the code reviewers noticed that the code used wcslen to compute the length of a string. He pointed out that the SDL Banned API page calls out strlen/wcslen as being banned</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Good News! strlen isn’t a banned API after all.</title><link>http://blogs.msdn.com/larryosterman/archive/2009/06/23/good-news-strlen-isn-t-a-banned-api-after-all.aspx#9800457</link><pubDate>Wed, 24 Jun 2009 02:11:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9800457</guid><dc:creator>Alexandre Grigoriev</dc:creator><description>&lt;p&gt;It makes perfect sense that mbslen is banned. Too easy to misuse number of MB characters as the string length. And if there is a malformed multi-byte character, who knows if mbslen won't barf. You can hope.&lt;/p&gt;
&lt;p&gt;strlen can turn bad, if you happen to use strncpy which doesn't always nul-terminate the buffer.&lt;/p&gt;</description></item><item><title>re: Good News! strlen isn’t a banned API after all.</title><link>http://blogs.msdn.com/larryosterman/archive/2009/06/23/good-news-strlen-isn-t-a-banned-api-after-all.aspx#9800468</link><pubDate>Wed, 24 Jun 2009 02:28:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9800468</guid><dc:creator>LarryOsterman</dc:creator><description>&lt;p&gt;Good point Alex - mbslen IS one of those icky APIs. &amp;nbsp;But the others aren't.&lt;/p&gt;
&lt;p&gt;And strlen isn't the problem with the strlen/strncpy usage - it's strncpy which is correctly on the list of banned APIs.&lt;/p&gt;
</description></item><item><title>re: Good News! strlen isn’t a banned API after all.</title><link>http://blogs.msdn.com/larryosterman/archive/2009/06/23/good-news-strlen-isn-t-a-banned-api-after-all.aspx#9800673</link><pubDate>Wed, 24 Jun 2009 05:40:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9800673</guid><dc:creator>Leo Davidson</dc:creator><description>&lt;p&gt;Is there any plan to add a safe version of MultiByteToWideChar?&lt;/p&gt;
&lt;p&gt;I appreciate and try to use the &amp;quot;safe&amp;quot; functions and it seems like this is a key API that's missed the treatment. (Maybe because it's in Win32 rather than the CRT.)&lt;/p&gt;
&lt;p&gt;As per the docs, it's very difficult to call safely. Very commonly used API, too, especially when dealing with internet traffic and binary data file formats (two scenarios where the safe APIs tend to be very important).&lt;/p&gt;
&lt;p&gt;(Of the top of my head, it's got issues with unterminated inputs, termination of inputs longer than your buffer, inputs that get truncated with half a surrogate at the end of the buffer (docs suggest the API deals with that on Vista but might mean something else), different API null-term behaviour depending on whether the input is null-terminated and/or whether you specify a length and/or whether the length includes the null. May be remembering incorrectly for some of them but that sort of thing. I had to write a little test app to see how the API behaved in some of those cases as it's not all documented.)&lt;/p&gt;
&lt;p&gt;I recently wrote code to convert UTF8 tags from music files into UTF16. (Even ignoring malicious input, there are so many badly written music taggers out there producing dodgy tags that you've got to be careful.) Writing &amp;amp; testing a wrapper function which, I hope, deals with all the cases was fiddly &amp;amp; time consuming and makes me wonder if I thought of everything.&lt;/p&gt;</description></item><item><title>re: Good News! strlen isn’t a banned API after all.</title><link>http://blogs.msdn.com/larryosterman/archive/2009/06/23/good-news-strlen-isn-t-a-banned-api-after-all.aspx#9800727</link><pubDate>Wed, 24 Jun 2009 06:15:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9800727</guid><dc:creator>mvadu</dc:creator><description>&lt;p&gt;Its nice to see your blog alive again Larry!! its been a while since you posted.. W7 Beta/RC audio must have uncovered some nasty bug in audio sub system keeping you away from bloging..&lt;/p&gt;
</description></item><item><title>re: Good News! strlen isn’t a banned API after all.</title><link>http://blogs.msdn.com/larryosterman/archive/2009/06/23/good-news-strlen-isn-t-a-banned-api-after-all.aspx#9800772</link><pubDate>Wed, 24 Jun 2009 06:37:40 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9800772</guid><dc:creator>Jeff</dc:creator><description>&lt;p&gt;OT, but ...&lt;/p&gt;
&lt;p&gt;Larry, welcome back! You've been missed. I'm sure you're busy with Windows 7 but I'm looking forward to more posts. You're one of a select few Microsoft blogs I read regularly.&lt;/p&gt;</description></item><item><title>re: Good News! strlen isn’t a banned API after all.</title><link>http://blogs.msdn.com/larryosterman/archive/2009/06/23/good-news-strlen-isn-t-a-banned-api-after-all.aspx#9803602</link><pubDate>Thu, 25 Jun 2009 16:58:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9803602</guid><dc:creator>Observer</dc:creator><description>&lt;p&gt;OT, but the table itself is fixed width, causing it to be truncated. &amp;nbsp;There is seriously no reason for it to be fixed width in this case. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Make fit to the width of the browser so that the contents aren't truncated.&lt;/p&gt;
&lt;p&gt;:)&lt;/p&gt;</description></item></channel></rss>