gcc/libstdc++-v3/testsuite/27_io
Jonathan Wakely e06d3f5dd7 libstdc++: Fix filesystem::path construction from COW string [PR 99805]
Calling the non-const data() member on a COW string makes it "leaked",
possibly resulting in reallocating the string to ensure a unique owner.

The path::_M_split_cmpts() member parses its _M_pathname string using
string_view objects and then calls _M_pathname.data() to find the offset
of each string_view from the start of the string. However because
_M_pathname is non-const that will cause a COW string to reallocate if
it happens to be shared with another string object. This results in the
offsets calculated for each component being wrong (i.e. undefined)
because the string views no longer refer to substrings of the
_M_pathname member. The fix is to use the parse.offset(c) member which
gets the offset safely.

The bug only happens for the path(string_type&&) constructor and only
for COW strings. When constructed from an lvalue string the string's
contents are copied rather than just incrementing the refcount, so
there's no reallocation when calling the non-const data() member. The
testsuite changes check the lvalue case anyway, because we should
probably change the deep copying to just be a refcount increment (by
adding a path(const string_type&) constructor or an overload for
__effective_range(const string_type&), for COW strings only).

libstdc++-v3/ChangeLog:

	PR libstdc++/99805
	* src/c++17/fs_path.cc (path::_M_split_cmpts): Do not call
	non-const member on _M_pathname, to avoid copy-on-write.
	* testsuite/27_io/filesystem/path/decompose/parent_path.cc:
	Check construction from strings that might be shared.
2021-04-07 16:39:24 +01:00
..
basic_filebuf Update copyright years. 2021-01-04 10:26:59 +01:00
basic_fstream Update copyright years. 2021-01-04 10:26:59 +01:00
basic_ifstream Update copyright years. 2021-01-04 10:26:59 +01:00
basic_ios Update copyright years. 2021-01-04 10:26:59 +01:00
basic_iostream Update copyright years. 2021-01-04 10:26:59 +01:00
basic_istream Update copyright years. 2021-01-04 10:26:59 +01:00
basic_istringstream libstdc++: Only use dynamic_cast in tests when RTTI is enabled 2021-02-12 14:30:13 +00:00
basic_ofstream Update copyright years. 2021-01-04 10:26:59 +01:00
basic_ostream libstdc++: XFAIL tests that depends on RTTI 2021-02-12 14:30:13 +00:00
basic_ostringstream libstdc++: Only use dynamic_cast in tests when RTTI is enabled 2021-02-12 14:30:13 +00:00
basic_streambuf Update copyright years. 2021-01-04 10:26:59 +01:00
basic_stringbuf Update copyright years. 2021-01-04 10:26:59 +01:00
basic_stringstream libstdc++: Only use dynamic_cast in tests when RTTI is enabled 2021-02-12 14:30:13 +00:00
basic_syncbuf Update copyright years. 2021-01-04 10:26:59 +01:00
basic_syncstream Update copyright years. 2021-01-04 10:26:59 +01:00
filesystem libstdc++: Fix filesystem::path construction from COW string [PR 99805] 2021-04-07 16:39:24 +01:00
fpos Update copyright years. 2021-01-04 10:26:59 +01:00
headers libstdc++: Do not assume std::FILE is complete [PR 99270] 2021-02-25 15:35:58 +00:00
ios_base Update copyright years. 2021-01-04 10:26:59 +01:00
manipulators Update copyright years. 2021-01-04 10:26:59 +01:00
objects Update copyright years. 2021-01-04 10:26:59 +01:00
types Update copyright years. 2021-01-04 10:26:59 +01:00
rvalue_streams-2.cc Update copyright years. 2021-01-04 10:26:59 +01:00
rvalue_streams.cc Update copyright years. 2021-01-04 10:26:59 +01:00