Skip to content

Commit

Permalink
text-motion: fix integer overflow in text_search_{forward,backward}
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Jan 10, 2016
1 parent 2191032 commit 713f90f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions text-motions.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,10 @@ size_t text_bracket_match_except(Text *txt, size_t pos, const char *except) {
}

size_t text_search_forward(Text *txt, size_t pos, Regex *regex) {
int start = pos + 1;
int end = text_size(txt);
size_t start = pos + 1;
size_t end = text_size(txt);
RegexMatch match[1];
bool found = !text_search_range_forward(txt, start, end - start, regex, 1, match, 0);
bool found = start < end && !text_search_range_forward(txt, start, end - start, regex, 1, match, 0);

if (!found) {
start = 0;
Expand All @@ -631,15 +631,15 @@ size_t text_search_forward(Text *txt, size_t pos, Regex *regex) {
}

size_t text_search_backward(Text *txt, size_t pos, Regex *regex) {
int start = 0;
int end = pos;
size_t start = 0;
size_t end = pos;
RegexMatch match[1];
bool found = !text_search_range_backward(txt, start, end, regex, 1, match, 0);

if (!found) {
start = pos + 1;
end = text_size(txt);
found = !text_search_range_backward(txt, start, end - start, regex, 1, match, 0);
found = start < end && !text_search_range_backward(txt, start, end - start, regex, 1, match, 0);
}

return found ? match[0].start : pos;
Expand Down

0 comments on commit 713f90f

Please sign in to comment.