]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix concatenation bug in filesystem::path
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 4 Jan 2019 11:43:09 +0000 (11:43 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 4 Jan 2019 11:43:09 +0000 (11:43 +0000)
When erasing a trailing empty filename component, the output iterator
was not decremented, causing the next component to be created at the
wrong position.

* src/filesystem/std-path.cc (path::operator+=(const path&)): Fix
incorrect treatment of empty filename after trailing slash.
* testsuite/27_io/filesystem/path/concat/path.cc: Test problem case.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@267574 138bc75d-0d04-0410-961f-82ee72b054a4

libstdc++-v3/ChangeLog
libstdc++-v3/src/filesystem/std-path.cc
libstdc++-v3/testsuite/27_io/filesystem/path/concat/path.cc

index e6a2dc2ba700c71368bde213a5edd390e53211b9..483a60224c9dd57dac7c20c6b59439a1f374f4b1 100644 (file)
@@ -1,5 +1,9 @@
 2019-01-04  Jonathan Wakely  <jwakely@redhat.com>
 
+       * src/filesystem/std-path.cc (path::operator+=(const path&)): Fix
+       incorrect treatment of empty filename after trailing slash.
+       * testsuite/27_io/filesystem/path/concat/path.cc: Test problem case.
+
        * testsuite/21_strings/basic_string/modifiers/assign/char/
        move_assign_optim.cc: Avoid spurious failure when -fno-inline added
        to test flags.
index bf6f37711ebd758c6dc2f3122fc880a982553b66..b7315ad1686370c3366db63c8396d9246852ed50 100644 (file)
@@ -945,7 +945,7 @@ path::operator+=(const path& p)
       else if (orig_filenamelen == 0 && it != last)
        {
          // Remove empty filename at end of original path.
-         _M_cmpts.erase(std::prev(output));
+         _M_cmpts.erase(--output);
        }
 
       if (it != last && it->_M_type() == _Type::_Root_name)
index b653219a7f759766e1c05319ec6cc5690a87ac64..e2a14bd8fccd669df6681952ef7e7087f585f34c 100644 (file)
@@ -59,9 +59,18 @@ test02()
   }
 }
 
+void
+test03()
+{
+  path p = "a/";
+  p += path("/b");
+  compare_paths(p, "a//b");
+}
+
 int
 main()
 {
   test01();
   test02();
+  test03();
 }