Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2020-11-02 21:55:03 +0300
committerJunio C Hamano <gitster@pobox.com>2020-11-02 23:15:50 +0300
commitb7879b0ba6ee1306a42227f7fd7f4e5f50409184 (patch)
tree32f328d974b2a59154e062edacda2158935d1fd7 /hashmap.h
parent97a39a4a930ebec9162f90ebd0412aed47d413d0 (diff)
hashmap: allow re-use after hashmap_free()
Previously, once map->table had been freed, any calls to hashmap_put(), hashmap_get(), or hashmap_remove() would cause a NULL pointer dereference (since hashmap_free_() also zeros the memory; without that zeroing, calling these functions would cause a use-after-free problem). Modify these functions to check for a NULL table and automatically allocate as needed. Also add a HASHMAP_INIT(fn, data) macro for initializing hashmaps on the stack without calling hashmap_init(). Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'hashmap.h')
-rw-r--r--hashmap.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/hashmap.h b/hashmap.h
index 904f61d6e1..3b0f2bcade 100644
--- a/hashmap.h
+++ b/hashmap.h
@@ -210,6 +210,9 @@ struct hashmap {
/* hashmap functions */
+#define HASHMAP_INIT(fn, data) { .cmpfn = fn, .cmpfn_data = data, \
+ .do_count_items = 1 }
+
/*
* Initializes a hashmap structure.
*