@matheusbsbs / matheus-bagliano / commits / 8d1675eb7f
Fork 0

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 <vd@FreeBSD.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Vasil Dimov committed Apr 15, 2020 at 20:32 UTC 8d1675eb7f7f76af834c72e72c8824410e874fec
1 file changed +4 -1
range-diff.c
+4 -1
@@ -123,16 +123,19 @@ static int read_patches(const char *range, struct string_list *list,
123 struct patch patch = { 0 };
124 struct strbuf root = STRBUF_INIT;
125 int linenr = 0;
126 + int orig_len;
127
128 in_header = 0;
129 strbuf_addch(&buf, '\n');
130 if (!util->diff_offset)
131 util->diff_offset = buf.len;
132 line[len - 1] = '\n';
133 + orig_len = len;
134 len = parse_git_diff_header(&root, &linenr, 0, line,
135 len, size, &patch);
136 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);
139 strbuf_addstr(&buf, " ## ");
140 if (patch.is_new > 0)
141 strbuf_addf(&buf, "%s (new)", patch.new_name);