diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2020-08-06 18:44:50 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2020-08-06 21:24:42 +0100 |
commit | 8b692f8b4c0e47bc8e11d9c3ab83049f68b2edbc (patch) | |
tree | 31644616fbb4589fded88cea1b069a5ef93c83c0 /libstdc++-v3 | |
parent | 9801353c9d8651808880f3550de52edaae74c2f2 (diff) | |
download | gcc-8b692f8b4c0e47bc8e11d9c3ab83049f68b2edbc.zip gcc-8b692f8b4c0e47bc8e11d9c3ab83049f68b2edbc.tar.gz gcc-8b692f8b4c0e47bc8e11d9c3ab83049f68b2edbc.tar.bz2 |
libstdc++: Fix unnecessary allocations in read_symlink [PR 96484]
libstdc++-v3/ChangeLog:
PR libstdc++/96484
* src/filesystem/ops.cc (fs::read_symlink): Return an error
immediately for non-symlinks.
* src/filesystem/std-ops.cc (fs::read_symlink): Likewise.
(cherry picked from commit 6a13a4e3f29fc4ce5eff96d74ba965c9fdc02184)
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/src/filesystem/ops.cc | 6 | ||||
-rw-r--r-- | libstdc++-v3/src/filesystem/std-ops.cc | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/libstdc++-v3/src/filesystem/ops.cc b/libstdc++-v3/src/filesystem/ops.cc index f04b4c5..4a14251 100644 --- a/libstdc++-v3/src/filesystem/ops.cc +++ b/libstdc++-v3/src/filesystem/ops.cc @@ -987,6 +987,12 @@ fs::path fs::read_symlink(const path& p, error_code& ec) ec.assign(errno, std::generic_category()); return result; } + else if (!fs::is_symlink(make_file_status(st))) + { + ec.assign(EINVAL, std::generic_category()); + return result; + } + std::string buf(st.st_size ? st.st_size + 1 : 128, '\0'); do { diff --git a/libstdc++-v3/src/filesystem/std-ops.cc b/libstdc++-v3/src/filesystem/std-ops.cc index 6d0bec4..8f3191c 100644 --- a/libstdc++-v3/src/filesystem/std-ops.cc +++ b/libstdc++-v3/src/filesystem/std-ops.cc @@ -1248,6 +1248,12 @@ fs::path fs::read_symlink(const path& p, error_code& ec) ec.assign(errno, std::generic_category()); return result; } + else if (!fs::is_symlink(make_file_status(st))) + { + ec.assign(EINVAL, std::generic_category()); + return result; + } + std::string buf(st.st_size ? st.st_size + 1 : 128, '\0'); do { |