Skip to content

Commit b275da3

Browse files
author
ochafik
committed
partial regex: add missing iterator end checks
1 parent 2ea5f5c commit b275da3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

common/regex-partial.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ common_regex_match common_regex::search(const std::string & input, size_t pos, b
3939
GGML_ASSERT(begin >= 0);
4040
const size_t end = input.size();//begin + group.length();
4141
GGML_ASSERT(begin <= end);
42-
res.groups.push_back(begin, end});
42+
res.groups.push_back({begin, end});
4343
return res;
4444
}
4545
}
@@ -80,9 +80,9 @@ std::string regex_to_reversed_partial_regex(const std::string & pattern) {
8080
auto start = it;
8181
++it;
8282
while (it != end) {
83-
if (*it == '\\' && (++it != end)) {
83+
if ((*it == '\\') && (++it != end)) {
8484
++it;
85-
} else if (*it == ']') {
85+
} else if ((it != end) && (*it == ']')) {
8686
break;
8787
} else {
8888
++it;
@@ -170,7 +170,7 @@ std::string regex_to_reversed_partial_regex(const std::string & pattern) {
170170
auto str = std::string("\\") + *it;
171171
sequence->push_back(str);
172172
++it;
173-
} else {
173+
} else if (it != end) {
174174
sequence->push_back(std::string(1, *it));
175175
++it;
176176
}

0 commit comments

Comments
 (0)