Skip to content

Commit 1e1ade1

Browse files
anderskgitster
authored andcommitted
describe: Do not use a flex array in struct commit_name
Now add_to_known_names overwrites commit_names in place when multiple tags point to the same commit. This will make it easier to store commit_names in a hash table. Signed-off-by: Anders Kaseorg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 56a5f3a commit 1e1ade1

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

builtin/describe.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct commit_name {
3838
unsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */
3939
unsigned name_checked:1;
4040
unsigned char sha1[20];
41-
char path[FLEX_ARRAY]; /* more */
41+
const char *path;
4242
};
4343
static const char *prio_names[] = {
4444
"head", "lightweight", "annotated",
@@ -85,15 +85,15 @@ static void add_to_known_names(const char *path,
8585
struct commit_name *e = commit->util;
8686
struct tag *tag = NULL;
8787
if (replace_name(e, prio, sha1, &tag)) {
88-
size_t len = strlen(path)+1;
89-
free(e);
90-
e = xmalloc(sizeof(struct commit_name) + len);
88+
if (!e) {
89+
e = xmalloc(sizeof(struct commit_name));
90+
commit->util = e;
91+
}
9192
e->tag = tag;
9293
e->prio = prio;
9394
e->name_checked = 0;
9495
hashcpy(e->sha1, sha1);
95-
memcpy(e->path, path, len);
96-
commit->util = e;
96+
e->path = path;
9797
}
9898
found_names = 1;
9999
}

0 commit comments

Comments
 (0)