diff options
author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2019-02-08 12:20:08 +0000 |
---|---|---|
committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2019-02-08 12:20:08 +0000 |
commit | 21d8a7728d368f9ea7733c24a638cb8184a1ec46 (patch) | |
tree | 91ade476254ab33295b53f096fb74b3dbb994286 /libstdc++-v3 | |
parent | b27702ad9684a1ab39a59667d3e2869490e65307 (diff) |
Fix std::filesystem::absolute for empty paths
Backport from mainline
2018-05-21 Jonathan Wakely <jwakely@redhat.com>
* src/filesystem/std-ops.cc (absolute): Report an error for empty
paths.
(weakly_canonical(const path&)): Do not call canonical on empty path.
(weakly_canonical(const path&, error_code&)): Likewise.
* testsuite/27_io/filesystem/operations/absolute.cc: Check for errors.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-8-branch@268682 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 9 | ||||
-rw-r--r-- | libstdc++-v3/src/filesystem/std-ops.cc | 16 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/filesystem/operations/absolute.cc | 6 |
3 files changed, 26 insertions, 5 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 83fcc335750..0d2e56eb35a 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,6 +1,15 @@ 2019-02-08 Jonathan Wakely <jwakely@redhat.com> Backport from mainline + 2018-05-21 Jonathan Wakely <jwakely@redhat.com> + + * src/filesystem/std-ops.cc (absolute): Report an error for empty + paths. + (weakly_canonical(const path&)): Do not call canonical on empty path. + (weakly_canonical(const path&, error_code&)): Likewise. + * testsuite/27_io/filesystem/operations/absolute.cc: Check for errors. + + Backport from mainline 2019-01-30 Jonathan Wakely <jwakely@redhat.com> PR libstdc++/89117 diff --git a/libstdc++-v3/src/filesystem/std-ops.cc b/libstdc++-v3/src/filesystem/std-ops.cc index 74868cd48e6..00e4f987fc3 100644 --- a/libstdc++-v3/src/filesystem/std-ops.cc +++ b/libstdc++-v3/src/filesystem/std-ops.cc @@ -84,13 +84,20 @@ fs::absolute(const path& p) fs::path fs::absolute(const path& p, error_code& ec) { + path ret; + if (p.empty()) + { + ec = make_error_code(std::errc::no_such_file_or_directory); + return ret; + } #ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS ec = std::make_error_code(errc::not_supported); - return {}; #else ec.clear(); - return current_path() / p; + ret = current_path(); + ret /= p; #endif + return ret; } namespace @@ -1513,7 +1520,8 @@ fs::weakly_canonical(const path& p) ++iter; } // canonicalize: - result = canonical(result); + if (!result.empty()) + result = canonical(result); // append the non-existing elements: while (iter != end) result /= *iter++; @@ -1551,7 +1559,7 @@ fs::weakly_canonical(const path& p, error_code& ec) ++iter; } // canonicalize: - if (!ec) + if (!ec && !result.empty()) result = canonical(result, ec); if (ec) result.clear(); diff --git a/libstdc++-v3/testsuite/27_io/filesystem/operations/absolute.cc b/libstdc++-v3/testsuite/27_io/filesystem/operations/absolute.cc index 4e472edd375..413a86758f0 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/operations/absolute.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/operations/absolute.cc @@ -31,7 +31,11 @@ void test01() { for (const path& p : __gnu_test::test_paths) - VERIFY( absolute(p).is_absolute() ); + { + std::error_code ec; + path abs = absolute(p, ec); + VERIFY( ec || abs.is_absolute() ); + } } void |