aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2020-05-10 09:59:34 +0100
committerNicholas Marriott <nicholas.marriott@gmail.com>2020-05-10 10:01:20 +0100
commit5fa377d9273ee609784acc538a5defa09feb3095 (patch)
treeed00c29347cf3b5d3a2e9c80f343b96b155df45b
parent79a9a7b931780b83add9d296a0dfc3745d4f0996 (diff)
downloadrtmux-5fa377d9273ee609784acc538a5defa09feb3095.tar.gz
rtmux-5fa377d9273ee609784acc538a5defa09feb3095.tar.bz2
rtmux-5fa377d9273ee609784acc538a5defa09feb3095.zip
Do not loop forever when search finds an empty match, GitHub issue 2203.
-rw-r--r--window-copy.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/window-copy.c b/window-copy.c
index 4104d2ad..95b4cc6e 100644
--- a/window-copy.c
+++ b/window-copy.c
@@ -2445,7 +2445,8 @@ window_copy_search_lr_regex(struct grid *gd, u_int *ppx, u_int *psx, u_int py,
len += gd->sx;
}
- if (regexec(reg, buf, 1, &regmatch, eflags) == 0) {
+ if (regexec(reg, buf, 1, &regmatch, eflags) == 0 &&
+ regmatch.rm_so != regmatch.rm_eo) {
foundx = first;
foundy = py;
window_copy_cstrtocellpos(gd, len, &foundx, &foundy,
@@ -2547,6 +2548,8 @@ window_copy_last_regex(struct grid *gd, u_int py, u_int first, u_int last,
foundy = py;
oldx = first;
while (regexec(preg, buf + px, 1, &regmatch, eflags) == 0) {
+ if (regmatch.rm_so == regmatch.rm_eo)
+ break;
window_copy_cstrtocellpos(gd, len, &foundx, &foundy,
buf + px + regmatch.rm_so);
if (foundy > py || foundx >= last)