Commit 90de04bc7f1b85b9c491bcd124f6178fad005de1

Stefan Sperling 2021-10-11T18:32:16

fix a segfault in edscript() introduced by my previous commit Found by our cherrypick regression tests.

diff --git a/lib/diff3.c b/lib/diff3.c
index 4619d89..9b91858 100644
--- a/lib/diff3.c
+++ b/lib/diff3.c
@@ -982,7 +982,7 @@ edscript(int n, struct diff3_state *d3s)
 	off_t len;
 	char *line = NULL;
 	size_t linesize = 0;
-	ssize_t linelen, k;
+	ssize_t linelen = 0, k;
 
 	for (; n > 0; n--) {
 		if (!d3s->overlap[n]) {
@@ -1013,7 +1013,7 @@ edscript(int n, struct diff3_state *d3s)
 					goto done;
 			}
 			err = diff_output(d3s->diffbuf, "%s%s\n",
-			    line[linelen] == '\n' ? ":" : "",
+			    linelen > 0 && line[linelen] == '\n' ? ":" : "",
 			    GOT_DIFF_CONFLICT_MARKER_SEP);
 			if (err)
 				goto done;