[trivialre] fix past-end-of-string access in MatchSubstring
Thanks goes to MSVC's string_view asserts that check this.
This commit is contained in:
parent
38abfd9038
commit
5273567470
|
@ -58,14 +58,14 @@ inline bool MatchSubstring(const Matcher& m, std::string_view str) {
|
|||
size_t sz = str.size();
|
||||
CB succeed = [](std::string_view str, bool line_start) { return true; };
|
||||
bool line_start = true;
|
||||
for (size_t i = 0; i <= sz; i++) {
|
||||
for (size_t i = 0; i < sz; i++) {
|
||||
if (m(str, line_start, succeed)) {
|
||||
return true;
|
||||
}
|
||||
line_start = (str[0] == '\n');
|
||||
str.remove_prefix(1);
|
||||
}
|
||||
return false;
|
||||
return m("", line_start, succeed);
|
||||
}
|
||||
|
||||
Matcher CompileREOrDie(std::string_view str);
|
||||
|
|
|
@ -154,6 +154,8 @@ TEST(TrivialRETest, Runnings) {
|
|||
{"^a", "+a", "-ba", "+b\na"},
|
||||
{"a$", "+a\nb", "+ba", "+b\na"},
|
||||
{"a$\\nb", "+a\nb"},
|
||||
{"$", "+", "+aaa"},
|
||||
{"^$", "+", "-aaa", "+aaa\n"},
|
||||
};
|
||||
|
||||
for (const auto& vec : cases2) {
|
||||
|
|
Loading…
Reference in New Issue