don't add chunks with zero offset to diffoffset list
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
diff --git a/lib/diffoffset.c b/lib/diffoffset.c
index 5f4d297..f702f13 100644
--- a/lib/diffoffset.c
+++ b/lib/diffoffset.c
@@ -93,27 +93,38 @@ got_diffoffset_free(struct got_diffoffset_chunks *chunks)
}
const struct got_error *
-got_diffoffset_add(struct got_diffoffset_chunks *chunks,
- int old_lineno, int old_length, int new_lineno, int new_length)
+add_chunk(struct got_diffoffset_chunks *chunks, int lineno, int offset)
{
- struct got_diffoffset_chunk *chunk1, *chunk2;
+ struct got_diffoffset_chunk *chunk;
- chunk1 = alloc_chunk(old_lineno, new_lineno - old_lineno);
- if (chunk1 == NULL)
+ chunk = alloc_chunk(lineno, offset);
+ if (chunk == NULL)
return got_error_from_errno("alloc_chunk");
- chunk2 = alloc_chunk(old_lineno + old_length,
- new_lineno - old_lineno + new_length - old_length);
- if (chunk2 == NULL) {
- const struct got_error *err =
- got_error_from_errno("alloc_chunk");
- free(chunk1);
- return err;
+ SIMPLEQ_INSERT_TAIL(chunks, chunk, entry);
+ return NULL;
+}
+
+
+const struct got_error *
+got_diffoffset_add(struct got_diffoffset_chunks *chunks,
+ int old_lineno, int old_length, int new_lineno, int new_length)
+{
+ const struct got_error *err = NULL;
+ int offset;
+
+ offset = new_lineno - old_lineno;
+ if (offset != 0) {
+ err = add_chunk(chunks, old_lineno, offset);
+ if (err)
+ return err;
}
- SIMPLEQ_INSERT_TAIL(chunks, chunk1, entry);
- SIMPLEQ_INSERT_TAIL(chunks, chunk2, entry);
- return NULL;
+ offset = new_lineno - old_lineno + new_length - old_length;
+ if (offset != 0)
+ err = add_chunk(chunks, old_lineno + old_length, offset);
+
+ return err;
}
int