summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Couder <chriscool@tuxfamily.org>2009-03-27 00:13:01 (GMT)
committerJunio C Hamano <gitster@pobox.com>2009-03-27 08:10:27 (GMT)
commitb09b868f7fee689483d00bea3d52c0f14a80386c (patch)
treec2d78825b88e34ce66b4b48e3642151297233dd3
parent747e25050bfef8f3a7c882954b654cf6d97fc63e (diff)
downloadgit-b09b868f7fee689483d00bea3d52c0f14a80386c.zip
git-b09b868f7fee689483d00bea3d52c0f14a80386c.tar.gz
git-b09b868f7fee689483d00bea3d52c0f14a80386c.tar.bz2
log-tree: fix patch filename computation in "git format-patch"
When using "git format-patch", "get_patch_filename" in "log-tree.c" calls "strbuf_splice" that could die with the following message: "`pos + len' is too far after the end of the buffer" if you have: buf->len < start_len + FORMAT_PATCH_NAME_MAX but: buf->len + suffix_len > start_len + FORMAT_PATCH_NAME_MAX This patch tries to get rid of that bug. [jc: w/ simplified logic] Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--log-tree.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/log-tree.c b/log-tree.c
index 56a3488..5bd29e6 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -187,17 +187,12 @@ void get_patch_filename(struct commit *commit, int nr, const char *suffix,
strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
if (commit) {
+ int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;
+
format_commit_message(commit, "%f", buf, DATE_NORMAL);
- /*
- * Replace characters at the end with the suffix if the
- * filename is too long
- */
- if (buf->len + suffix_len > FORMAT_PATCH_NAME_MAX + start_len)
- strbuf_splice(buf,
- start_len + FORMAT_PATCH_NAME_MAX - suffix_len,
- suffix_len, suffix, suffix_len);
- else
- strbuf_addstr(buf, suffix);
+ if (max_len < buf->len)
+ strbuf_setlen(buf, max_len);
+ strbuf_addstr(buf, suffix);
}
}