Subject: [Boost-bugs] [Boost C++ Libraries] #5670: Construction from a character array leads to path with an embedded zero terminator
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-07-05 10:49:11
#5670: Construction from a character array leads to path with an embedded zero
terminator
-----------------------------------------+----------------------------------
Reporter: davidjward30@⦠| Owner: bemandawes
Type: Bugs | Status: new
Milestone: To Be Determined | Component: filesystem
Version: Boost 1.44.0 | Severity: Regression
Keywords: constructor character array |
-----------------------------------------+----------------------------------
Boost filesystem v3.
Demonstrated with an example:
wchar_t filename[256];
filename[0]=L'D';
filename[1]=0;
std::wstring s(filename);
std::cout << "Length of s: " << s.length() << " " << std::endl;
boost::filesystem::path p2(filename);
std::cout << "Length of p: " << p2.native().length() << std::endl;
Displays:
Length of s: 1
Length of p: 255
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.
I would expect length of p to be 1 with the path ending at the first zero
terminator.
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.
An obvious workaround is to do:
boost::filesystem::path p2(&filename[0]);
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/5670> 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:06 UTC