public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/giulianob/heads/autopar_rebase2)] libstdc++: Fix unnecessary allocations in read_symlink [PR 96484]
@ 2020-08-18  1:32 Giuliano Belinassi
  0 siblings, 0 replies; only message in thread
From: Giuliano Belinassi @ 2020-08-18  1:32 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:080673c0d1557f87d3a28fd63054ca5a0c1c8f1c

commit 080673c0d1557f87d3a28fd63054ca5a0c1c8f1c
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Aug 6 18:44:50 2020 +0100

    libstdc++: Fix unnecessary allocations in read_symlink [PR 96484]
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/96484
            * src/c++17/fs_ops.cc (fs::read_symlink): Return an error
            immediately for non-symlinks.
            * src/filesystem/ops.cc (fs::read_symlink): Likewise.

Diff:
---
 libstdc++-v3/src/c++17/fs_ops.cc   | 6 ++++++
 libstdc++-v3/src/filesystem/ops.cc | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/libstdc++-v3/src/c++17/fs_ops.cc b/libstdc++-v3/src/c++17/fs_ops.cc
index 873f93aacfc..c685b1824f9 100644
--- a/libstdc++-v3/src/c++17/fs_ops.cc
+++ b/libstdc++-v3/src/c++17/fs_ops.cc
@@ -1180,6 +1180,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/ops.cc b/libstdc++-v3/src/filesystem/ops.cc
index 29ea9c0ce87..8c8854bf28e 100644
--- a/libstdc++-v3/src/filesystem/ops.cc
+++ b/libstdc++-v3/src/filesystem/ops.cc
@@ -998,6 +998,12 @@ fs::path fs::read_symlink(const path& p [[gnu::unused]], 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
     {


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-18  1:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-18  1:32 [gcc(refs/users/giulianob/heads/autopar_rebase2)] libstdc++: Fix unnecessary allocations in read_symlink [PR 96484] Giuliano Belinassi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).