decouple line_offsets/nlines output params of got_object_blob_dump_to_file()
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
diff --git a/lib/object.c b/lib/object.c
index a8e56d3..a74eaa7 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -1300,8 +1300,8 @@ got_object_blob_dump_to_file(size_t *filesize, int *nlines,
break;
buf = got_object_blob_get_read_buf(blob);
i = hdrlen;
- if (line_offsets && nlines) {
- if (*line_offsets == NULL) {
+ if (nlines) {
+ if (line_offsets && *line_offsets == NULL) {
/* Have some data but perhaps no '\n'. */
noffsets = 1;
*nlines = 1;
@@ -1323,7 +1323,7 @@ got_object_blob_dump_to_file(size_t *filesize, int *nlines,
continue;
}
(*nlines)++;
- if (noffsets < *nlines) {
+ if (line_offsets && noffsets < *nlines) {
off_t *o = recallocarray(*line_offsets,
noffsets, *nlines,
sizeof(**line_offsets));
@@ -1336,8 +1336,10 @@ got_object_blob_dump_to_file(size_t *filesize, int *nlines,
*line_offsets = o;
noffsets = *nlines;
}
- off = total_len + i - hdrlen + 1;
- (*line_offsets)[*nlines - 1] = off;
+ if (line_offsets) {
+ off = total_len + i - hdrlen + 1;
+ (*line_offsets)[*nlines - 1] = off;
+ }
i++;
}
}