Opened 11 years ago

Closed 11 years ago

#5670 closed Bugs (duplicate)

Construction from a character array leads to path with an embedded zero terminator

Reported by: davidjward30@… Owned by: Beman Dawes
Milestone: To Be Determined Component: filesystem
Version: Boost 1.44.0 Severity: Regression
Keywords: constructor character array Cc:

Description

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]);

Change History (2)

comment:1 by davidjward30@…, 11 years ago

Platform is Windows 7 64-bit. Compiler is Visual Studio 2010, compiling to x86/Win32.

comment:2 by Beman Dawes, 11 years ago

Resolution: duplicate
Status: newclosed

This was reported at the time of the release and fixed August 19, 2010. See http://svn.boost.org/trac/boost/changeset/64928

Please install a more recent version of Boost to eliminate your problem.

--Beman

Note: See TracTickets for help on using tickets.