From 8177e62c18464f6284f8a1ad55bed9d6c653e943 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Tue, 3 Jan 2017 21:18:24 +0100
Subject: [PATCH] screen: examine the whole line when painting, to set the
 correct info

In order to determine the correct multidata for a line that doesn't
have such data yet, the whole line must be examined, not just the
part that fits within the screen width.

This fixes https://savannah.gnu.org/bugs/?49978.
---
 src/winio.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/winio.c b/src/winio.c
index 947176eb..40c353bb 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2539,11 +2539,10 @@ void edit_draw(filestruct *fileptr, const char *converted, int
 		 * looking only after an end match, if there is one. */
 		start_col = (paintlen == 0) ? 0 : endmatch.rm_eo;
 
-		while (start_col < endpos) {
+		while (TRUE) {
 		    if (regexec(varnish->start, fileptr->data + start_col,
 				1, &startmatch, (start_col == 0) ?
-				0 : REG_NOTBOL) == REG_NOMATCH ||
-				start_col + startmatch.rm_so >= endpos)
+				0 : REG_NOTBOL) == REG_NOMATCH)
 			/* No more starts on this line. */
 			break;
 
@@ -2575,16 +2574,13 @@ void edit_draw(filestruct *fileptr, const char *converted, int
 					strnlenpt(fileptr->data,
 					endmatch.rm_eo) - start - x_start);
 
-			    assert(0 <= x_start && x_start < editwincols);
-
 			    mvwaddnstr(edit, line, x_start + margin,
 					converted + index, paintlen);
-			    if (paintlen > 0) {
-				fileptr->multidata[varnish->id] = CSTARTENDHERE;
+
+			    fileptr->multidata[varnish->id] = CSTARTENDHERE;
 #ifdef DEBUG
     fprintf(stderr, "  Marking for id %i  line %i as CSTARTENDHERE\n", varnish->id, line);
 #endif
-			    }
 			}
 			start_col = endmatch.rm_eo;
 			/* Skip over a zero-length match. */
@@ -2604,8 +2600,6 @@ void edit_draw(filestruct *fileptr, const char *converted, int
 			if (end_line == NULL)
 			    break;
 
-			assert(0 <= x_start && x_start < editwincols);
-
 			/* Paint the rest of the line. */
 			mvwaddnstr(edit, line, x_start + margin, converted + index, -1);
 			fileptr->multidata[varnish->id] = CENDAFTER;
-- 
GitLab