Skip to content

Commit 8d1675e

Browse files
vasildgitster
authored andcommitted
range-diff: avoid negative string precision
If the supplied integer for "precision" is negative in `"%.*s", len, line` then it is ignored. So the current code is equivalent to just `"%s", line` because it is executed only if `len` is negative. Fix this by saving the value of `len` before overwriting it with the return value of `parse_git_diff_header()`. Signed-off-by: Vasil Dimov <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8cf5156 commit 8d1675e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

range-diff.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,19 @@ static int read_patches(const char *range, struct string_list *list,
123123
struct patch patch = { 0 };
124124
struct strbuf root = STRBUF_INIT;
125125
int linenr = 0;
126+
int orig_len;
126127

127128
in_header = 0;
128129
strbuf_addch(&buf, '\n');
129130
if (!util->diff_offset)
130131
util->diff_offset = buf.len;
131132
line[len - 1] = '\n';
133+
orig_len = len;
132134
len = parse_git_diff_header(&root, &linenr, 0, line,
133135
len, size, &patch);
134136
if (len < 0)
135-
die(_("could not parse git header '%.*s'"), (int)len, line);
137+
die(_("could not parse git header '%.*s'"),
138+
orig_len, line);
136139
strbuf_addstr(&buf, " ## ");
137140
if (patch.is_new > 0)
138141
strbuf_addf(&buf, "%s (new)", patch.new_name);

0 commit comments

Comments
 (0)