diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-03-14 13:35:31 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-03-14 14:22:35 +0100 |
| commit | 644c2708478617ce78e2d12f973a6c496ee5dbf5 (patch) | |
| tree | e5e23887ee9c53d6b8676b9fbf4d8f35e6d42083 /text-regex.c | |
| parent | 64b3c105b92d5676afcf2dfe38431326c2951fed (diff) | |
| download | vis-644c2708478617ce78e2d12f973a6c496ee5dbf5.tar.gz vis-644c2708478617ce78e2d12f973a6c496ee5dbf5.tar.xz | |
text-regex: fix possible infinite loop when searching backwards
Diffstat (limited to 'text-regex.c')
| -rw-r--r-- | text-regex.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/text-regex.c b/text-regex.c index c4134aa..c3d1cb2 100644 --- a/text-regex.c +++ b/text-regex.c @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <string.h> #include <regex.h> #include "text-regex.h" @@ -58,7 +59,16 @@ int text_search_range_backward(Text *txt, size_t pos, size_t len, Regex *r, size pmatch[i].start = match[i].rm_so == -1 ? EPOS : pos + (size_t)(cur - buf) + match[i].rm_so; pmatch[i].end = match[i].rm_eo == -1 ? EPOS : pos + (size_t)(cur - buf) + match[i].rm_eo; } - cur += match[0].rm_eo; + if (match[0].rm_so == 0 && match[0].rm_eo == 0) { + /* empty match at the beginning of cur, advance to next line */ + if ((cur = strchr(cur, '\n'))) + cur++; + else + break; + + } else { + cur += match[0].rm_eo; + } } free(buf); return ret; |
