public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR libstdc++/90557 fix path assignment that alters source
@ 2019-05-22 22:14 Jonathan Wakely
  2019-05-28 19:43 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Wakely @ 2019-05-22 22:14 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 412 bytes --]

	PR libstdc++/90557
	* src/c++17/fs_path.cc (path::_List::operator=(const _List&)): Fix
	reversed arguments to uninitialized_copy_n.
	* testsuite/27_io/filesystem/path/assign/copy.cc: Check that source
	is unchanged by copy assignment.
	* testsuite/util/testsuite_fs.h (compare_paths): Use std::equal to
	compare path components.

Tested x86_64-linux, committed to trunk. I'll backport it to
gcc-9-branch too.



[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 3082 bytes --]

commit edcb23ee78d194cbb518a151c7edfbb2895c48d3
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed May 22 22:07:50 2019 +0100

    PR libstdc++/90557 fix path assignment that alters source
    
            PR libstdc++/90557
            * src/c++17/fs_path.cc (path::_List::operator=(const _List&)): Fix
            reversed arguments to uninitialized_copy_n.
            * testsuite/27_io/filesystem/path/assign/copy.cc: Check that source
            is unchanged by copy assignment.
            * testsuite/util/testsuite_fs.h (compare_paths): Use std::equal to
            compare path components.

diff --git a/libstdc++-v3/src/c++17/fs_path.cc b/libstdc++-v3/src/c++17/fs_path.cc
index 605f62cbf81..8e01bf510d3 100644
--- a/libstdc++-v3/src/c++17/fs_path.cc
+++ b/libstdc++-v3/src/c++17/fs_path.cc
@@ -278,8 +278,8 @@ path::_List::operator=(const _List& other)
 	    to[i]._M_pathname.reserve(from[i]._M_pathname.length());
 	  if (newsize > oldsize)
 	    {
-	      std::uninitialized_copy_n(to + oldsize, newsize - oldsize,
-					from + oldsize);
+	      std::uninitialized_copy_n(from + oldsize, newsize - oldsize,
+					to + oldsize);
 	      impl->_M_size = newsize;
 	    }
 	  else if (newsize < oldsize)
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc
index 775dbffad36..6aa25ae12ef 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/assign/copy.cc
@@ -64,10 +64,25 @@ test03()
   VERIFY( ptr2 == p.begin()->c_str() );
 }
 
+void
+test04()
+{
+  // PR libstdc++/90557
+  path p1 = "a/b/c";
+  const path p2 = "d/e";
+  const path p3 = p2;
+  p1.clear();
+  p1 = p2;
+  __gnu_test::compare_paths(p1, p2);
+  __gnu_test::compare_paths(p1, p3);
+  __gnu_test::compare_paths(p2, p3);
+}
+
 int
 main()
 {
   test01();
   test02();
   test03();
+  test04();
 }
diff --git a/libstdc++-v3/testsuite/util/testsuite_fs.h b/libstdc++-v3/testsuite/util/testsuite_fs.h
index baba90eaa0c..b2a5ee6e655 100644
--- a/libstdc++-v3/testsuite/util/testsuite_fs.h
+++ b/libstdc++-v3/testsuite/util/testsuite_fs.h
@@ -30,6 +30,7 @@ namespace test_fs = std::filesystem;
 #include <experimental/filesystem>
 namespace test_fs = std::experimental::filesystem;
 #endif
+#include <algorithm>
 #include <fstream>
 #include <string>
 #include <cstdio>
@@ -62,10 +63,15 @@ namespace __gnu_test
     PATH_CHK( p1, p2, is_relative );
     auto d1 = std::distance(p1.begin(), p1.end());
     auto d2 = std::distance(p2.begin(), p2.end());
-    if( d1 != d2 )
+    if (d1 != d2)
       throw test_fs::filesystem_error(
-	  "distance(begin, end)", p1, p2,
+	  "distance(begin1, end1) != distance(begin2, end2)", p1, p2,
 	  std::make_error_code(std::errc::invalid_argument) );
+    if (!std::equal(p1.begin(), p1.end(), p2.begin(), p2.end()))
+      throw test_fs::filesystem_error(
+	  "!equal(begin1, end1, begin2, end2)", p1, p2,
+	  std::make_error_code(std::errc::invalid_argument) );
+
   }
 
   const std::string test_paths[] = {

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] PR libstdc++/90557 fix path assignment that alters source
  2019-05-22 22:14 [PATCH] PR libstdc++/90557 fix path assignment that alters source Jonathan Wakely
@ 2019-05-28 19:43 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2019-05-28 19:43 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 627 bytes --]

On 22/05/19 23:14 +0100, Jonathan Wakely wrote:
>	PR libstdc++/90557
>	* src/c++17/fs_path.cc (path::_List::operator=(const _List&)): Fix
>	reversed arguments to uninitialized_copy_n.
>	* testsuite/27_io/filesystem/path/assign/copy.cc: Check that source
>	is unchanged by copy assignment.
>	* testsuite/util/testsuite_fs.h (compare_paths): Use std::equal to
>	compare path components.

I should have used the three-argument version of std::equal, because
the four-argument one is not available in C++11.

Fixed with this patch, tested powerpc64le-linux and committed to
trunk. This needs to be backported togcc-9-branch too.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 1078 bytes --]

commit ee46741a1ff05926900d655273ef7f84054e3f62
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue May 28 15:52:58 2019 +0100

    Fix C++14-only code in testsuite utility
    
            * testsuite/util/testsuite_fs.h (compare_paths): Use three-argument
            form of std::equals for C++11 compatibility.

diff --git a/libstdc++-v3/testsuite/util/testsuite_fs.h b/libstdc++-v3/testsuite/util/testsuite_fs.h
index b2a5ee6e655..fe42845ac4f 100644
--- a/libstdc++-v3/testsuite/util/testsuite_fs.h
+++ b/libstdc++-v3/testsuite/util/testsuite_fs.h
@@ -67,9 +67,9 @@ namespace __gnu_test
       throw test_fs::filesystem_error(
 	  "distance(begin1, end1) != distance(begin2, end2)", p1, p2,
 	  std::make_error_code(std::errc::invalid_argument) );
-    if (!std::equal(p1.begin(), p1.end(), p2.begin(), p2.end()))
+    if (!std::equal(p1.begin(), p1.end(), p2.begin()))
       throw test_fs::filesystem_error(
-	  "!equal(begin1, end1, begin2, end2)", p1, p2,
+	  "!equal(begin1, end1, begin2)", p1, p2,
 	  std::make_error_code(std::errc::invalid_argument) );
 
   }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-05-28 19:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-22 22:14 [PATCH] PR libstdc++/90557 fix path assignment that alters source Jonathan Wakely
2019-05-28 19:43 ` Jonathan Wakely

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).