From 7e5524bb667674d0a8e6298a32f24c6398099276 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 20 Jan 2017 10:58:15 +0100 Subject: [PATCH] painting: do not let a match for 'end' overlap a match for 'start' During precalculation and in step_two, we begin looking for an end match only after the full start match, not merely one byte beyond its starting point. So do that too when searching backward for an unpaired start match. Also, index can never be zero here, because if the match was of length zero, this piece of code will have been skipped by the preceding goto. So we can always use REG_NOTBOL here. (That goto is wrong, by the way: https://savannah.gnu.org/bugs/?50078, but that will follow later.) --- src/winio.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/winio.c b/src/winio.c index b04625e7..b60caa11 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2481,19 +2481,17 @@ void edit_draw(filestruct *fileptr, const char *converted, * a start match. Is there a start on that line not followed * by an end on that line? */ while (TRUE) { - index += startmatch.rm_so; - startmatch.rm_eo -= startmatch.rm_so; - if (regexec(varnish->end, start_line->data + index + - startmatch.rm_eo, 0, NULL, - (index + startmatch.rm_eo == 0) ? - 0 : REG_NOTBOL) == REG_NOMATCH) + index += startmatch.rm_eo; + if (regexec(varnish->end, start_line->data + index, + 0, NULL, REG_NOTBOL) == REG_NOMATCH) /* No end found after this start. */ break; - index++; if (regexec(varnish->start, start_line->data + index, 1, &startmatch, REG_NOTBOL) == REG_NOMATCH) /* No later start on this line. */ goto step_two; + if (startmatch.rm_so == startmatch.rm_eo) + index++; } /* Indeed, there is a start without an end on that line. */