summaryrefslogtreecommitdiff
path: root/src/hashmap.c
diff options
context:
space:
mode:
authorQuinn Stephens <quinn@osmora.org>2025-06-09 21:52:03 -0400
committerQuinn Stephens <quinn@osmora.org>2025-06-09 21:52:03 -0400
commitc1abbf40752027d5c0f8f4853312a882ae3088d6 (patch)
tree9d1b80c479cdb703ca8fc3ae424ee9f1ddecaf0b /src/hashmap.c
parent065d60fc962136d03a8a74eb235901aa14d87593 (diff)
Fix hashmap_find()
Modified hashmap_find() to properly fit the way lists work (where the list struct is technically a list entry at the end of a circular list). If this had not been fixed, hashmap_find() probably would have run into some sort of infinite loop or segmentation fault when it failed to find a matching entry. Signed-off-by: Quinn Stephens <quinn@osmora.org>
Diffstat (limited to 'src/hashmap.c')
-rw-r--r--src/hashmap.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/hashmap.c b/src/hashmap.c
index cc7f2db..d4d6358 100644
--- a/src/hashmap.c
+++ b/src/hashmap.c
@@ -46,16 +46,18 @@ hashmap_add(struct hashmap map, struct hashmap_entry *entry)
struct hashmap_entry *
hashmap_find(struct hashmap map, hash_t hash)
{
- struct hashmap_entry *head, *entry;
+ struct list *list;
+ struct hashmap_entry *entry;
- entry = head = (struct hashmap_entry *)map.rows[hash % map.row_count].head;
- do {
+ list = &map.rows[hash % map.row_count];
+ entry = (struct hashmap_entry *)list->head;
+ while (entry != (struct hashmap_entry *)list) {
if (entry->hash == hash) {
return entry;
}
entry = (struct hashmap_entry *)entry->list_entry.next;
- } while (entry != head);
+ }
return NULL;
}