From 94907aa5349a613e80e42224b6b20f18057d4414 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg <bensberg@justemail.net> Date: Fri, 20 Jan 2017 13:31:18 +0100 Subject: [PATCH] painting: do not bluntly ignore zero-length start matches -- handle them The segmentation fault that this causes when both start and end match are zero-length will be tackled later (https://savannah.gnu.org/bugs/?50056). This fixes https://savannah.gnu.org/bugs/?50078. Inspired-by: Elia Geretto <elia.f.geretto@gmail.com> --- src/winio.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/winio.c b/src/winio.c index b60caa11..1ba4a861 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2473,25 +2473,24 @@ void edit_draw(filestruct *fileptr, const char *converted, start_line->multidata[varnish->id] == CSTARTENDHERE)) goto step_two; - /* Skip over a zero-length regex match. */ - if (startmatch.rm_so == startmatch.rm_eo) - goto tail_of_loop; - /* Now start_line is the first line before fileptr containing * a start match. Is there a start on that line not followed * by an end on that line? */ while (TRUE) { + /* Begin searching for an end after the start match. */ index += startmatch.rm_eo; + /* If the start match is zero-length, don't get stuck. */ + if (startmatch.rm_so == startmatch.rm_eo) + index++; + + /* If there is no end after this last start, good. */ if (regexec(varnish->end, start_line->data + index, 0, NULL, REG_NOTBOL) == REG_NOMATCH) - /* No end found after this start. */ break; + /* If there is no later start on this line, next step. */ 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. */ -- GitLab