[libcxx] r307171 - Fix a bug in regex_Iterator where it would report zero-length matches forever. Reported as http://llvm.org/PR33681. Thanks to Karen Arutyunov for the report.

Marshall Clow via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 5 09:37:19 PDT 2017


Author: marshall
Date: Wed Jul  5 09:37:19 2017
New Revision: 307171

URL: http://llvm.org/viewvc/llvm-project?rev=307171&view=rev
Log:
Fix a bug in regex_Iterator where it would report zero-length matches forever. Reported as http://llvm.org/PR33681. Thanks to Karen Arutyunov for the report.

Modified:
    libcxx/trunk/include/regex
    libcxx/trunk/test/std/re/re.iter/re.regiter/re.regiter.incr/post.pass.cpp

Modified: libcxx/trunk/include/regex
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/regex?rev=307171&r1=307170&r2=307171&view=diff
==============================================================================
--- libcxx/trunk/include/regex (original)
+++ libcxx/trunk/include/regex Wed Jul  5 09:37:19 2017
@@ -6142,7 +6142,7 @@ regex_iterator<_BidirectionalIterator, _
 {
     __flags_ |= regex_constants::__no_update_pos;
     _BidirectionalIterator __start = __match_[0].second;
-    if (__match_.empty())
+    if (__match_[0].first == __match_[0].second)
     {
         if (__start == __end_)
         {

Modified: libcxx/trunk/test/std/re/re.iter/re.regiter/re.regiter.incr/post.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.iter/re.regiter/re.regiter.incr/post.pass.cpp?rev=307171&r1=307170&r2=307171&view=diff
==============================================================================
--- libcxx/trunk/test/std/re/re.iter/re.regiter/re.regiter.incr/post.pass.cpp (original)
+++ libcxx/trunk/test/std/re/re.iter/re.regiter/re.regiter.incr/post.pass.cpp Wed Jul  5 09:37:19 2017
@@ -95,4 +95,22 @@ int main()
         assert((*i2).position() == 0);
         assert((*i2).str() == "555-1234");
     }
+    { // http://llvm.org/PR33681
+        std::regex rex(".*");
+        const char foo[] = "foo";
+    //  The -1 is because we don't want the implicit null from the array.
+        std::cregex_iterator i(std::begin(foo), std::end(foo) - 1, rex);
+        std::cregex_iterator e;
+        assert(i != e);
+        assert((*i).size() == 1);
+        assert((*i).str() == "foo");
+
+        ++i;
+        assert(i != e);
+        assert((*i).size() == 1);
+        assert((*i).str() == "");
+
+        ++i;
+        assert(i == e);
+    }
 }




More information about the cfe-commits mailing list