Skip to content

Commit e4cb369

Browse files
gitsterdscho
authored andcommitted
Merge branch 'backport/jk/range-diff-fixes'
"git range-diff" code clean-up. Needed to pacify modern GCC versions. * jk/range-diff-fixes: range-diff: use ssize_t for parsed "len" in read_patches() range-diff: handle unterminated lines in read_patches() range-diff: drop useless "offset" variable from read_patches()
2 parents 3c7896e + c025b4b commit e4cb369

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

range-diff.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,6 @@ struct patch_util {
2525
struct object_id oid;
2626
};
2727

28-
static size_t find_end_of_line(char *buffer, unsigned long size)
29-
{
30-
char *eol = memchr(buffer, '\n', size);
31-
32-
if (!eol)
33-
return size;
34-
35-
*eol = '\0';
36-
return eol + 1 - buffer;
37-
}
38-
3928
/*
4029
* Reads the patches into a string list, with the `util` field being populated
4130
* as struct object_id (will need to be free()d).
@@ -48,7 +37,7 @@ static int read_patches(const char *range, struct string_list *list,
4837
struct patch_util *util = NULL;
4938
int in_header = 1;
5039
char *line, *current_filename = NULL;
51-
int offset, len;
40+
ssize_t len;
5241
size_t size;
5342

5443
strvec_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges",
@@ -83,11 +72,18 @@ static int read_patches(const char *range, struct string_list *list,
8372

8473
line = contents.buf;
8574
size = contents.len;
86-
for (offset = 0; size > 0; offset += len, size -= len, line += len) {
75+
for (; size > 0; size -= len, line += len) {
8776
const char *p;
77+
char *eol;
78+
79+
eol = memchr(line, '\n', size);
80+
if (eol) {
81+
*eol = '\0';
82+
len = eol + 1 - line;
83+
} else {
84+
len = size;
85+
}
8886

89-
len = find_end_of_line(line, size);
90-
line[len - 1] = '\0';
9187
if (skip_prefix(line, "commit ", &p)) {
9288
if (util) {
9389
string_list_append(list, buf.buf)->util = util;
@@ -129,7 +125,8 @@ static int read_patches(const char *range, struct string_list *list,
129125
strbuf_addch(&buf, '\n');
130126
if (!util->diff_offset)
131127
util->diff_offset = buf.len;
132-
line[len - 1] = '\n';
128+
if (eol)
129+
*eol = '\n';
133130
orig_len = len;
134131
len = parse_git_diff_header(&root, &linenr, 0, line,
135132
len, size, &patch);

0 commit comments

Comments
 (0)