Commit 971405a7e47997a87d869bc30b3fca98083395dc

Stefan Sperling 2019-10-09T07:32:03

do not abuse d3s->fp[0] as a local variable in diff3.c's readin()

diff --git a/lib/diff3.c b/lib/diff3.c
index 8209ffc..5532125 100644
--- a/lib/diff3.c
+++ b/lib/diff3.c
@@ -575,16 +575,17 @@ static const struct got_error *
 readin(size_t *n, char *name, struct diff **dd, struct diff3_state *d3s)
 {
 	const struct got_error *err = NULL;
+	FILE *f;
 	int a, b, c, d;
 	char kind, *p;
 	size_t i;
 
 	*n = 0;
 
-	d3s->fp[0] = fopen(name, "r");
-	if (d3s->fp[0] == NULL)
+	f = fopen(name, "r");
+	if (f == NULL)
 		return got_error_from_errno2("fopen", name);
-	err = getchange(&p, d3s->fp[0], d3s);
+	err = getchange(&p, f, d3s);
 	if (err)
 		return err;
 	for (i = 0; p; i++) {
@@ -615,7 +616,7 @@ readin(size_t *n, char *name, struct diff **dd, struct diff3_state *d3s)
 		(*dd)[i].new.from = c;
 		(*dd)[i].new.to = d;
 
-		err = getchange(&p, d3s->fp[0], d3s);
+		err = getchange(&p, f, d3s);
 		if (err)
 			return err;
 	}
@@ -625,7 +626,7 @@ readin(size_t *n, char *name, struct diff **dd, struct diff3_state *d3s)
 		(*dd)[i].new.from = (*dd)[i - 1].new.to;
 	}
 
-	if (fclose(d3s->fp[0]) != 0)
+	if (fclose(f) != 0)
 		err = got_error_from_errno("fclose");
 
 	*n = i;