summaryrefslogtreecommitdiff
path: root/builtin/tag.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-03-28 19:46:23 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-03-30 21:59:50 (GMT)
commitb0ceab98d72a4861a8cea061487169fb5468b736 (patch)
tree1994fcfed5274f1aab90cbca342d288584dcd608 /builtin/tag.c
parent977db6b4bf36e76dfd5d0a4ae8b8258334d4b1ea (diff)
downloadgit-b0ceab98d72a4861a8cea061487169fb5468b736.zip
git-b0ceab98d72a4861a8cea061487169fb5468b736.tar.gz
git-b0ceab98d72a4861a8cea061487169fb5468b736.tar.bz2
tag: use strbuf to format tag header
We format the tag header into a fixed 1024-byte buffer. But since the tag-name and tagger ident can be arbitrarily large, we may unceremoniously die with "tag header too big". Let's just use a strbuf instead. Note that it looks at first glance like we can just format this directly into the "buf" strbuf where it will ultimately go. But that buffer may already contain the tag message, and we have no easy way to prepend formatted data to a strbuf (we can only splice in an already-generated buffer). This isn't a performance-critical path, so going through an extra buffer isn't a big deal. Signed-off-by: Jeff King <peff@peff.net>
Diffstat (limited to 'builtin/tag.c')
-rw-r--r--builtin/tag.c27
1 files changed, 12 insertions, 15 deletions
diff --git a/builtin/tag.c b/builtin/tag.c
index ad29be6..045e7ad 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -231,26 +231,22 @@ static void create_tag(const unsigned char *object, const char *tag,
unsigned char *prev, unsigned char *result)
{
enum object_type type;
- char header_buf[1024];
- int header_len;
+ struct strbuf header = STRBUF_INIT;
char *path = NULL;
type = sha1_object_info(object, NULL);
if (type <= OBJ_NONE)
die(_("bad object type."));
- header_len = snprintf(header_buf, sizeof(header_buf),
- "object %s\n"
- "type %s\n"
- "tag %s\n"
- "tagger %s\n\n",
- sha1_to_hex(object),
- typename(type),
- tag,
- git_committer_info(IDENT_STRICT));
-
- if (header_len > sizeof(header_buf) - 1)
- die(_("tag header too big."));
+ strbuf_addf(&header,
+ "object %s\n"
+ "type %s\n"
+ "tag %s\n"
+ "tagger %s\n\n",
+ sha1_to_hex(object),
+ typename(type),
+ tag,
+ git_committer_info(IDENT_STRICT));
if (!opt->message_given) {
int fd;
@@ -288,7 +284,8 @@ static void create_tag(const unsigned char *object, const char *tag,
if (!opt->message_given && !buf->len)
die(_("no tag message?"));
- strbuf_insert(buf, 0, header_buf, header_len);
+ strbuf_insert(buf, 0, header.buf, header.len);
+ strbuf_release(&header);
if (build_tag_object(buf, opt->sign, result) < 0) {
if (path)