Boost C++ Libraries: Ticket #5670: Construction from a character array leads to path with an embedded zero terminator https://svn.boost.org/trac10/ticket/5670 <p> Boost filesystem v3. </p> <p> Demonstrated with an example: </p> <p> wchar_t filename<a class="changeset" href="https://svn.boost.org/trac10/changeset/256" title="This commit was manufactured by cvs2svn to create branch 'MAIN'.">[256]</a>; </p> <p> filename<a class="missing changeset" title="No changeset 0 in the repository">[0]</a>=L'D'; filename<a class="changeset" href="https://svn.boost.org/trac10/changeset/1" title="Import core sources for SVNmanger 0.38 ">[1]</a>=0; std::wstring s(filename); std::cout &lt;&lt; "Length of s: " &lt;&lt; s.length() &lt;&lt; " " &lt;&lt; std::endl; </p> <p> boost::filesystem::path p2(filename); std::cout &lt;&lt; "Length of p: " &lt;&lt; p2.native().length() &lt;&lt; std::endl; </p> <p> Displays: </p> <p> Length of s: 1 Length of p: 255 </p> <p> When initializing a std::wstring with a character array, the embedded zero terminator is taken in to account. However, with filesystem::path, the resulting path ends up longer than expected with an embedded zero terminator. </p> <p> I would expect length of p to be 1 with the path ending at the first zero terminator. </p> <p> This bug leads to all sorts of hard to find bugs as many operations seem to work fine, but calling path::filename() results in an empty string. </p> <p> An obvious workaround is to do: </p> <p> boost::filesystem::path p2(&amp;filename<a class="missing changeset" title="No changeset 0 in the repository">[0]</a>); </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5670 Trac 1.4.3 davidjward30@… Tue, 05 Jul 2011 10:57:45 GMT <link>https://svn.boost.org/trac10/ticket/5670#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5670#comment:1</guid> <description> <p> Platform is Windows 7 64-bit. Compiler is Visual Studio 2010, compiling to x86/Win32. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Beman Dawes</dc:creator> <pubDate>Wed, 06 Jul 2011 12:10:32 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5670#comment:2 https://svn.boost.org/trac10/ticket/5670#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">duplicate</span> </li> </ul> <p> This was reported at the time of the release and fixed August 19, 2010. See <a class="ext-link" href="http://svn.boost.org/trac/boost/changeset/64928"><span class="icon">​</span>http://svn.boost.org/trac/boost/changeset/64928</a> </p> <p> Please install a more recent version of Boost to eliminate your problem. </p> <p> --Beman </p> Ticket