summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2020-04-15 20:32:25 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-04-16 01:32:48 (GMT)
commit8d1675eb7f7f76af834c72e72c8824410e874fec (patch)
tree25a2bf401bf645c83fd775c08c67433d0033bb7a
parent8cf51561d1e15e8f5ad907df00884a7596737dcd (diff)
downloadgit-8d1675eb7f7f76af834c72e72c8824410e874fec.zip
git-8d1675eb7f7f76af834c72e72c8824410e874fec.tar.gz
git-8d1675eb7f7f76af834c72e72c8824410e874fec.tar.bz2
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>
-rw-r--r--range-diff.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/range-diff.c b/range-diff.c
index 5cc920b..40af086 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -123,16 +123,19 @@ static int read_patches(const char *range, struct string_list *list,
struct patch patch = { 0 };
struct strbuf root = STRBUF_INIT;
int linenr = 0;
+ int orig_len;
in_header = 0;
strbuf_addch(&buf, '\n');
if (!util->diff_offset)
util->diff_offset = buf.len;
line[len - 1] = '\n';
+ orig_len = len;
len = parse_git_diff_header(&root, &linenr, 0, line,
len, size, &patch);
if (len < 0)
- die(_("could not parse git header '%.*s'"), (int)len, line);
+ die(_("could not parse git header '%.*s'"),
+ orig_len, line);
strbuf_addstr(&buf, " ## ");
if (patch.is_new > 0)
strbuf_addf(&buf, "%s (new)", patch.new_name);