[Boost-bugs] [Boost C++ Libraries] #10388: null character at end of string from filesystem::temp_directory_path

Subject: [Boost-bugs] [Boost C++ Libraries] #10388: null character at end of string from filesystem::temp_directory_path
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-08-21 12:15:13


#10388: null character at end of string from filesystem::temp_directory_path
------------------------------+------------------------
 Reporter: anonymous | Owner: bemandawes
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: filesystem
  Version: Boost 1.56.0 | Severity: Problem
 Keywords: |
------------------------------+------------------------
 The null character at end of string causes very interesting bugs that are
 hard to debug.

 Workaround we learned to use is .c_str():

    filesystem::path temp_path = filesystem::temp_directory_path( ec
 ).c_str();

 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).

 Solution:
 replace lines
    buf.pop_back();
    path p(buf.begin(), buf.end());
 with
    path p(buf.begin());

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/10388>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:16 UTC