summaryrefslogtreecommitdiffstats
path: root/hashmap.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-02-22 17:44:32 -0500
committerJunio C Hamano <gitster@pobox.com>2016-02-22 14:51:09 -0800
commit96ffc06f72f693d80f05059a1f0e5ca9007d5f1b (patch)
tree8f4587b3132a422757280f3d4f7bc302230efd7c /hashmap.c
parent3733e6946465d4a3a1d89026a5ec911d3af339ab (diff)
downloadgit-96ffc06f72f693d80f05059a1f0e5ca9007d5f1b.tar.gz
git-96ffc06f72f693d80f05059a1f0e5ca9007d5f1b.tar.xz
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 'hashmap.c')
-rw-r--r--hashmap.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/hashmap.c b/hashmap.c
index f693839cb..b10b64222 100644
--- a/hashmap.c
+++ b/hashmap.c
@@ -256,10 +256,9 @@ const void *memintern(const void *data, size_t len)
e = hashmap_get(&map, &key, data);
if (!e) {
/* not found: create it */
- e = xmallocz(sizeof(struct pool_entry) + len);
+ FLEX_ALLOC_MEM(e, data, data, len);
hashmap_entry_init(e, key.ent.hash);
e->len = len;
- memcpy(e->data, data, len);
hashmap_add(&map, e);
}
return e->data;