Opened 10 years ago

Closed 9 years ago

#7784 closed Bugs (invalid)

[PATCH] Overlapping strings are not properly handled by string::algo::find_all

Reported by: cedstrom@… Owned by: Marshall Clow
Milestone: To Be Determined Component: string_algo
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

See attached test case. There should be two matches in the following test case, one at index 0 and one at index 1, but boost::string::algorithm::find_all only finds one at index 0. I suspect the bug is that the string match erroneously restarts from the end of the previous match, not from beginning of the previous match + 1.

Attachments (1)

OverlappingStringTest.cpp (624 bytes ) - added by cedstrom@… 10 years ago.
Overlapping String Test Case

Download all attachments as: .zip

Change History (8)

by cedstrom@…, 10 years ago

Attachment: OverlappingStringTest.cpp added

Overlapping String Test Case

comment:1 by anonymous, 10 years ago

Patch which I believe fixes this:

Index: boost-trunk/boost/algorithm/string/find_iterator.hpp
===================================================================
--- boost-trunk/boost/algorithm/string/find_iterator.hpp	(revision 82112)
+++ boost-trunk/boost/algorithm/string/find_iterator.hpp	(working copy)
@@ -132,7 +132,10 @@
             // increment
             void increment()
             {
-                m_Match=this->do_find(m_Match.end(),m_End);
+                if(m_Match.begin() == m_Match.end())
+                    m_Match=this->do_find(m_Match.end(),m_End);
+                else
+                    m_Match=this->do_find(m_Match.begin()+1,m_End);
             }
 
             // comparison

comment:2 by anonymous, 10 years ago

Summary: Overlapping strings are not properly handled by string::algo::find_all[PATCH] Overlapping strings are not properly handled by string::algo::find_all

comment:3 by Marshall Clow, 10 years ago

Applied patch and added test case in [82117]. Thanks for the patch!

comment:4 by Marshall Clow, 10 years ago

Resolution: fixed
Status: newclosed

In [82238] merge fix to release.

comment:5 by Steven Watanabe, 10 years ago

Resolution: fixed
Status: closedreopened

Marshall, I don't think that this patch should have been applied. I believe that the library is intended to return non-overlapping matches. Rationale: (1) find_all is in split.hpp, the documentation says: "Split algorithms can be used to divide a string into several parts...." (2) For the sake of consistency, find_all, replace_all, and erase_all, should all use the same set of matches. The patch breaks this. (3) boost::regex_iterator also finds non-overlapping matches.

comment:6 by Marshall Clow, 9 years ago

This fix broke other stuff. See #9063.

I'm considering reverting it.

If you have objections, now would be a good time to speak up.

Last edited 9 years ago by Marshall Clow (previous) (diff)

comment:7 by Marshall Clow, 9 years ago

Resolution: invalid
Status: reopenedclosed

No one complained.

Reverting this.

Note: See TracTickets for help on using tickets.