diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-01-10 11:52:02 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-01-10 12:45:52 +0100 |
| commit | 713f90fd5dacb768731fa48b93a873bd37e085ad (patch) | |
| tree | 424f4c6e9bb2ac9e1ed09f907f4ff3447dce720d /text-motions.c | |
| parent | 21910326b4b5989179f194526b4bba2c3a676754 (diff) | |
| download | vis-713f90fd5dacb768731fa48b93a873bd37e085ad.tar.gz vis-713f90fd5dacb768731fa48b93a873bd37e085ad.tar.xz | |
text-motion: fix integer overflow in text_search_{forward,backward}
Diffstat (limited to 'text-motions.c')
| -rw-r--r-- | text-motions.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/text-motions.c b/text-motions.c index 8d49122..824f3a9 100644 --- a/text-motions.c +++ b/text-motions.c @@ -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; @@ -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; |
