vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 3a0dc3204a1f8405d111438b6570df70ddb6418f parent 2e0b03a5124d97ac75bcb17becf52c38b7fd680c Author: Marc André Tanner <mat@brain-dump.org> Date: Mon, 14 Mar 2016 13:35:31 +0100 text-regex: fix possible infinite loop when searching backwards Diffstat:
| M | text-regex.c | | | 12 | +++++++++++- |
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git 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;