Merge branch 'jk/tighten-alloc' into maint
authorJunio C Hamano <gitster@pobox.com>
Fri, 9 Sep 2016 04:36:00 +0000 (21:36 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 9 Sep 2016 04:36:00 +0000 (21:36 -0700)
Small code and comment clean-up.

* jk/tighten-alloc:
receive-pack: use FLEX_ALLOC_MEM in queue_command()
correct FLEXPTR_* example in comment

builtin/receive-pack.c
git-compat-util.h
index a744437b5876171250d4731d181f7b30e5444187..05d04400f5f0a8dbe9674207a41507fb9aa56f85 100644 (file)
@@ -1375,11 +1375,9 @@ static struct command **queue_command(struct command **tail,
 
        refname = line + 82;
        reflen = linelen - 82;
-       cmd = xcalloc(1, st_add3(sizeof(struct command), reflen, 1));
+       FLEX_ALLOC_MEM(cmd, ref_name, refname, reflen);
        hashcpy(cmd->old_sha1, old_sha1);
        hashcpy(cmd->new_sha1, new_sha1);
-       memcpy(cmd->ref_name, refname, reflen);
-       cmd->ref_name[reflen] = '\0';
        *tail = cmd;
        return &cmd->next;
 }
index 9eab471264ab6a22af3e5eb4a0a97f510de19a7e..b4b7f44952f2f1c53b6a35e99b7831df1adfabb6 100644 (file)
@@ -802,7 +802,7 @@ extern FILE *fopen_for_writing(const char *path);
  * you can do:
  *
  *   struct foo *f;
- *   FLEX_ALLOC_STR(f, name, src);
+ *   FLEXPTR_ALLOC_STR(f, name, src);
  *
  * and "name" will point to a block of memory after the struct, which will be
  * freed along with the struct (but the pointer can be repointed anywhere).