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>
master
Benno Schulenberg 2017-01-20 13:31:18 +01:00
parent 7e5524bb66
commit 94907aa534
1 changed files with 11 additions and 12 deletions

View File

@ -2473,25 +2473,24 @@ void edit_draw(filestruct *fileptr, const char *converted,
start_line->multidata[varnish->id] == CSTARTENDHERE)) start_line->multidata[varnish->id] == CSTARTENDHERE))
goto step_two; 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 /* Now start_line is the first line before fileptr containing
* a start match. Is there a start on that line not followed * a start match. Is there a start on that line not followed
* by an end on that line? */ * by an end on that line? */
while (TRUE) { while (TRUE) {
/* Begin searching for an end after the start match. */
index += startmatch.rm_eo; index += startmatch.rm_eo;
if (regexec(varnish->end, start_line->data + index, /* If the start match is zero-length, don't get stuck. */
0, NULL, REG_NOTBOL) == REG_NOMATCH)
/* No end found after this start. */
break;
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) if (startmatch.rm_so == startmatch.rm_eo)
index++; 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)
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)
goto step_two;
} }
/* Indeed, there is a start without an end on that line. */ /* Indeed, there is a start without an end on that line. */