{"id":35463,"date":"2005-06-02T08:58:33","date_gmt":"2005-06-02T08:58:33","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2005\/06\/02\/if-strncpy-is-so-dangerous-why-does-visual-studio-2005-still-support-it\/"},"modified":"2005-06-02T08:58:33","modified_gmt":"2005-06-02T08:58:33","slug":"if-strncpy-is-so-dangerous-why-does-visual-studio-2005-still-support-it","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20050602-33\/?p=35463\/","title":{"rendered":"If strncpy is so dangerous, why does Visual Studio 2005 still support it?"},"content":{"rendered":"<p>In response to the news that <a href=\"http:\/\/weblogs.asp.net\/oldnewthing\/archive\/2005\/01\/07\/348437.aspx\"> <code>strncpy<\/code> is so dangerous<\/a>, at least one person has called for Visual Studio to <a href=\"http:\/\/www.arstdesign.com\/BBS\/BulletinBoard.php?qs_id=2221\"> revoke support for such a dangerous function<\/a>, considering the continued support for the function grounds for holding the compiler manufacturer liable for any defects in programs compiled with that compiler.\n Well, for one thing, while it&#8217;s true that <code>strncpy<\/code> is dangerous if used improperly, it is still a valid function, and my original discussion explained the history behind <code>strncpy<\/code> and the very specific scenario in which it is still useful. It just so happens that most people don&#8217;t use the function in the manner it was intended, but instead treat it as a sort of &#8220;copy string with a character limit&#8221; function, which it isn&#8217;t really.\n For another thing, just because something is dangerous doesn&#8217;t mean it shouldn&#8217;t be supported.  Pointers and casts are dangerous, but I don&#8217;t see them disappearing from C or C++ any time soon.<\/p>\n<p> Third, support for <code>strncpy<\/code> is mandated by the C standard. If you removed it, you couldn&#8217;t call yourself a C compiler any more. (Not to mention breaking compatibility with existing source code that uses the <code>strncpy<\/code> function.  How would you like it if you bought a so-called C compiler and found that it couldn&#8217;t compile a large class of valid C programs?) <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In response to the news that strncpy is so dangerous, at least one person has called for Visual Studio to revoke support for such a dangerous function, considering the continued support for the function grounds for holding the compiler manufacturer liable for any defects in programs compiled with that compiler. Well, for one thing, while [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-35463","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>In response to the news that strncpy is so dangerous, at least one person has called for Visual Studio to revoke support for such a dangerous function, considering the continued support for the function grounds for holding the compiler manufacturer liable for any defects in programs compiled with that compiler. Well, for one thing, while [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/35463","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=35463"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/35463\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=35463"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=35463"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=35463"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}