adjust preadline() and ignoreline() to match diff(1) again
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
diff --git a/lib/diffreg.c b/lib/diffreg.c
index 157aa95..37e980d 100644
--- a/lib/diffreg.c
+++ b/lib/diffreg.c
@@ -962,6 +962,7 @@ preadline(int fd, size_t rlen, off_t off)
static int
ignoreline(char *line)
{
+ free(line);
return 0; /* do not ignore any lines */
}
@@ -983,6 +984,7 @@ restart:
if (args->diff_format != D_IFDEF && a > b && c > d)
return (0);
if (args->ignore_pats != NULL) {
+ char *line;
/*
* All lines in the change, insert, or delete must
* match an ignore pattern for the change to be
@@ -990,30 +992,24 @@ restart:
*/
if (a <= b) { /* Changes and deletes. */
for (i = a; i <= b; i++) {
- char *line = preadline(fileno(f1),
+ line = preadline(fileno(f1),
ds->ixold[i] - ds->ixold[i - 1],
ds->ixold[i - 1]);
if (line == NULL)
return (-1);
- if (!ignoreline(line)) {
- free(line);
+ if (!ignoreline(line))
goto proceed;
- }
- free(line);
}
}
if (a > b || c <= d) { /* Changes and inserts. */
for (i = c; i <= d; i++) {
- char *line = preadline(fileno(f2),
+ line = preadline(fileno(f2),
ds->ixnew[i] - ds->ixnew[i - 1],
ds->ixnew[i - 1]);
if (line == NULL)
return (-1);
- if (!ignoreline(line)) {
- free(line);
+ if (!ignoreline(line))
goto proceed;
- }
- free(line);
}
}
return (0);