Bill Fisher: This patch fixes a less likely case where '\b' can back up into invalid memory, when driven by a regex_iterator (for case 1, see r185273 or http://llvm.org/bugs/show_bug.cgi?id=16240)

The attached test program also supplies a test for the case 1 fix in r185273.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@186089 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant
2013-07-11 15:32:55 +00:00
parent 37c17ed07d
commit e840208989
2 changed files with 66 additions and 2 deletions

View File

@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <regex>
// template <class BidirectionalIterator, class Allocator, class charT, class traits>
// bool
// regex_search(BidirectionalIterator first, BidirectionalIterator last,
// match_results<BidirectionalIterator, Allocator>& m,
// const basic_regex<charT, traits>& e,
// regex_constants::match_flag_type flags = regex_constants::match_default);
#include <regex>
#include <string>
#include <list>
#include <cassert>
int main()
{
// This regex_iterator uses regex_search(__wrap_iter<_Iter> __first, ...)
// Test for http://llvm.org/bugs/show_bug.cgi?id=16240 fixed in r185273.
{
std::string s{"aaaa a"};
std::regex re{"\\ba"};
std::sregex_iterator it{s.begin(), s.end(), re};
std::sregex_iterator end{};
assert(it->position(0) == 0);
assert(it->length(0) == 1);
++it;
assert(it->position(0) == 5);
assert(it->length(0) == 1);
++it;
assert(it == end);
}
// This regex_iterator uses regex_search(_BidirectionalIterator __first, ...)
{
std::string s{"aaaa a"};
std::list<char> l{s.begin(), s.end()};
std::regex re{"\\ba"};
std::regex_iterator<std::list<char>::iterator> it{l.begin(), l.end(), re};
std::regex_iterator<std::list<char>::iterator> end{};
assert(it->position(0) == 0);
assert(it->length(0) == 1);
++it;
assert(it->position(0) == 5);
assert(it->length(0) == 1);
++it;
assert(it == end);
}
}