summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-02-22 22:44:32 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-02-22 22:51:09 (GMT)
commit96ffc06f72f693d80f05059a1f0e5ca9007d5f1b (patch)
tree8f4587b3132a422757280f3d4f7bc302230efd7c /refs.c
parent3733e6946465d4a3a1d89026a5ec911d3af339ab (diff)
downloadgit-96ffc06f72f693d80f05059a1f0e5ca9007d5f1b.zip
git-96ffc06f72f693d80f05059a1f0e5ca9007d5f1b.tar.gz
git-96ffc06f72f693d80f05059a1f0e5ca9007d5f1b.tar.bz2
convert trivial cases to FLEX_ARRAY macros
Using FLEX_ARRAY macros reduces the amount of manual computation size we have to do. It also ensures we don't overflow size_t, and it makes sure we write the same number of bytes that we allocated. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/refs.c b/refs.c
index 1d9e2a7..2d86445 100644
--- a/refs.c
+++ b/refs.c
@@ -761,10 +761,8 @@ void ref_transaction_free(struct ref_transaction *transaction)
static struct ref_update *add_update(struct ref_transaction *transaction,
const char *refname)
{
- size_t len = strlen(refname) + 1;
- struct ref_update *update = xcalloc(1, sizeof(*update) + len);
-
- memcpy((char *)update->refname, refname, len); /* includes NUL */
+ struct ref_update *update;
+ FLEX_ALLOC_STR(update, refname, refname);
ALLOC_GROW(transaction->updates, transaction->nr + 1, transaction->alloc);
transaction->updates[transaction->nr++] = update;
return update;