[LLVMbugs] [Bug 21751] New: regex iterator endless loop
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Thu Dec 4 10:19:38 PST 2014
http://llvm.org/bugs/show_bug.cgi?id=21751
Bug ID: 21751
Summary: regex iterator endless loop
Product: libc++
Version: unspecified
Hardware: Macintosh
OS: All
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: mclow.lists at gmail.com
CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
Classification: Unclassified
Given the following code:
----
#include <iostream>
#include <regex>
#include <string>
void print(const char* t, const std::string& s, const std::ssub_match& sub)
{
std::cout << " " << t << ": " << (sub.matched ? "matched " : "unmatched")
<< ", "
"length() = " << sub.length() << ", str() = '" << sub.str() << "\', "
"pair = (" << sub.first - s.begin() << ", " << sub.second - s.begin()
<< "), "
"'" << std::string(sub.first, sub.second) << '\'' << std::endl;
}
int main()
{
const std::regex e("z*");
const std::string s("ab");
int i = 0;
for (auto&& it = std::sregex_iterator(s.begin(), s.end(), e), end =
std::sregex_iterator();
it != end; ++it) {
std::cout << i++ << ':' << std::endl;
print("prefix", s, it->prefix());
print("match ", s, (*it)[0]);
std::cout << std::endl;
}
}
----
The loop runs forever.
Suggested output from <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64140>:
----
0:
prefix: unmatched, length() = 0, str() = '', pair = (0, 0), ''
match : matched , length() = 0, str() = '', pair = (0, 0), ''
1:
prefix: matched , length() = 1, str() = 'a', pair = (0, 1), 'a'
match : matched , length() = 0, str() = '', pair = (1, 1), ''
2:
prefix: matched , length() = 1, str() = 'b', pair = (1, 2), 'b'
match : matched , length() = 0, str() = '', pair = (2, 2), ''
----
Thanks to Jonathan Wakely for the report.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141204/d3cd0c1a/attachment.html>
More information about the llvm-bugs
mailing list