Boost C++ Libraries: Ticket #10388: null character at end of string from filesystem::temp_directory_path https://svn.boost.org/trac10/ticket/10388 <p> The null character at end of string causes very interesting bugs that are hard to debug. </p> <p> Workaround we learned to use is .c_str(): </p> <blockquote> <p> filesystem::path temp_path = filesystem::temp_directory_path( ec ).c_str(); </p> </blockquote> <p> Cause of bug: GetTempPathW(0, 0) returns the size of buffer enought to contain the path, but is might be bigger than (path length + 1). (It rarely happens, but happens.) However the function filesystem::temp_directory_path expects it to be exactly (path length + 1). </p> <p> Solution: replace lines </p> <blockquote> <p> buf.pop_back(); path p(buf.begin(), buf.end()); </p> </blockquote> <p> with </p> <blockquote> <p> path p(buf.begin()); </p> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10388 Trac 1.4.3 Beman Dawes Sat, 10 Jan 2015 14:34:14 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/10388#comment:1 https://svn.boost.org/trac10/ticket/10388#comment:1 <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">fixed</span> </li> </ul> <p> Fixed. A path member function remove_trailing_separator() was added publicly since this may be useful to users. </p> <p> Thanks, </p> <p> --Beman </p> Ticket anonymous Wed, 29 Jul 2015 11:03:08 GMT status, version changed; resolution deleted https://svn.boost.org/trac10/ticket/10388#comment:2 https://svn.boost.org/trac10/ticket/10388#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.56.0</span> → <span class="trac-field-new">Boost 1.57.0</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> The bug is not fixed as of version 1.57. It has nothing to do with `trailing separator'. </p> <p> Again: `The null character at end of string causes very interesting bugs ...'. </p> <p> The tested solution: replace lines </p> <p> <strong>buf.pop_back();</strong> </p> <p> <strong>path p(buf.begin(), buf.end());</strong> </p> <p> with </p> <p> <strong>path p(buf.begin());</strong> </p> <p> in file \libs\filesystem\src\operations.cpp </p> <p> The problem is that string returned by GetTempPathW sometimes contain 2 null characters. That means that 1 null character becomes a part of returned path in buggy code, because the code makes assumption that returned string contains exactly 1 null character. </p> <p> ... </p> <p> Is explanation ok? Or should I just send a patch? </p> Ticket Beman Dawes Sat, 29 Aug 2015 12:15:19 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/10388#comment:3 https://svn.boost.org/trac10/ticket/10388#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Oops! The trailing_separator comment applied to a different ticket. </p> <p> Are you sure you are looking at the current state of filesystem? GetTempPathW is no longer used. Please take a look at the develop branch at <a class="ext-link" href="https://github.com/boostorg/filesystem"><span class="icon">​</span>https://github.com/boostorg/filesystem</a>, and do submit a patch if you think there is still a problem, and then reopen the ticket again. </p> <p> Thanks, </p> <p> --Beman </p> Ticket