oidmap: ensure map is initialized
Ensure that an oidmap is initialized before attempting to add, remove, or retrieve an entry by simply performing the initialization step before accessing the underlying hashmap. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Williams committed
Dec 22, 2017 at 15:27 UTC
e2a5a028c778febb6776da16ab18fb4de79014f0
1 file changed
+11
oidmap.c
+11
@@ -33,12 +33,19 @@ void oidmap_free(struct oidmap *map, int free_entries)
33
34
void *oidmap_get(const struct oidmap *map, const struct object_id *key)
35
{
36
+ if (!map->map.cmpfn)
37
+ return NULL;
38
+
39
return hashmap_get_from_hash(&map->map, hash(key), key);
40
}
41
42
void *oidmap_remove(struct oidmap *map, const struct object_id *key)
43
{
44
struct hashmap_entry entry;
45
+
46
+ if (!map->map.cmpfn)
47
+ oidmap_init(map, 0);
48
+
49
hashmap_entry_init(&entry, hash(key));
50
return hashmap_remove(&map->map, &entry, key);
51
}
@@ -46,6 +53,10 @@ void *oidmap_remove(struct oidmap *map, const struct object_id *key)
53
void *oidmap_put(struct oidmap *map, void *entry)
54
{
55
struct oidmap_entry *to_put = entry;
56
+
57
+ if (!map->map.cmpfn)
58
+ oidmap_init(map, 0);
59
+
60
hashmap_entry_init(&to_put->internal_entry, hash(&to_put->oid));
61
return hashmap_put(&map->map, to_put);
62
}