check for errors from increase() in diff3 code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
diff --git a/lib/diff3.c b/lib/diff3.c
index 2c11ef0..83909d8 100644
--- a/lib/diff3.c
+++ b/lib/diff3.c
@@ -160,7 +160,8 @@ static int edit(struct diff *, int, int, struct diff3_state *);
static char *getchange(FILE *, struct diff3_state *);
static char *get_line(FILE *, size_t *, struct diff3_state *);
static int number(char **);
-static ssize_t readin(char *, struct diff **, struct diff3_state *);
+static const struct got_error *readin(size_t *, char *, struct diff **,
+ struct diff3_state *);
static int ed_patch_lines(struct rcs_lines *, struct rcs_lines *);
static int skip(int, int, char *, struct diff3_state *);
static int edscript(int, struct diff3_state *);
@@ -428,10 +429,13 @@ diff3_internal(char *dp13, char *dp23, char *path1, char *path2, char *path3,
err = increase(d3s);
if (err)
return err;
- if ((m = readin(dp13, &d3s->d13, d3s)) < 0)
- return got_error_from_errno();
- if ((n = readin(dp23, &d3s->d23, d3s)) < 0)
- return got_error_from_errno();
+
+ err = readin(&m, dp13, &d3s->d13, d3s);
+ if (err)
+ return err;
+ err = readin(&n, dp23, &d3s->d23, d3s);
+ if (err)
+ return err;
if ((d3s->fp[0] = fopen(path1, "r")) == NULL)
return got_error_from_errno();
@@ -562,19 +566,23 @@ ed_patch_lines(struct rcs_lines *dlines, struct rcs_lines *plines)
* since the vector is processed in one sequential pass.
* The vector could be optimized out of existence)
*/
-static ssize_t
-readin(char *name, struct diff **dd, struct diff3_state *d3s)
+static const struct got_error *
+readin(size_t *n, char *name, struct diff **dd, struct diff3_state *d3s)
{
+ const struct got_error *err = NULL;
int a, b, c, d;
char kind, *p;
size_t i;
d3s->fp[0] = fopen(name, "r");
if (d3s->fp[0] == NULL)
- return (-1);
+ return got_error_from_errno();
for (i = 0; (p = getchange(d3s->fp[0], d3s)); i++) {
- if (i >= d3s->szchanges - 1)
- increase(d3s); /* XXX check error! */
+ if (i >= d3s->szchanges - 1) {
+ err = increase(d3s);
+ if (err)
+ return err;
+ }
a = b = number(&p);
if (*p == ',') {
p++;
@@ -605,7 +613,7 @@ readin(char *name, struct diff **dd, struct diff3_state *d3s)
(void)fclose(d3s->fp[0]);
- return (i);
+ return NULL;
}
static int