Skip to content

Commit e2a5a02

Browse files
bmwillgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3013dff commit e2a5a02

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

oidmap.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,30 @@ void oidmap_free(struct oidmap *map, int free_entries)
3333

3434
void *oidmap_get(const struct oidmap *map, const struct object_id *key)
3535
{
36+
if (!map->map.cmpfn)
37+
return NULL;
38+
3639
return hashmap_get_from_hash(&map->map, hash(key), key);
3740
}
3841

3942
void *oidmap_remove(struct oidmap *map, const struct object_id *key)
4043
{
4144
struct hashmap_entry entry;
45+
46+
if (!map->map.cmpfn)
47+
oidmap_init(map, 0);
48+
4249
hashmap_entry_init(&entry, hash(key));
4350
return hashmap_remove(&map->map, &entry, key);
4451
}
4552

4653
void *oidmap_put(struct oidmap *map, void *entry)
4754
{
4855
struct oidmap_entry *to_put = entry;
56+
57+
if (!map->map.cmpfn)
58+
oidmap_init(map, 0);
59+
4960
hashmap_entry_init(&to_put->internal_entry, hash(&to_put->oid));
5061
return hashmap_put(&map->map, to_put);
5162
}

0 commit comments

Comments
 (0)