diff --git a/src/UDPC_HashMap.c b/src/UDPC_HashMap.c index 502ac87..8fdabbb 100644 --- a/src/UDPC_HashMap.c +++ b/src/UDPC_HashMap.c @@ -349,14 +349,16 @@ void UDPC_HashMap_itercall(UDPC_HashMap *hm, void (*fn)(void*, char*), void *use { char *data = UDPC_Deque_index_ptr( hm->buckets[x], 4 + hm->unitSize, y); - fn(userData, data + 4); + if(hm->unitSize > 0) { fn(userData, data + 4); } + else { fn(userData, data); } } } for(int x = 0; x * (4 + hm->unitSize) < hm->overflow->size; ++x) { char *data = UDPC_Deque_index_ptr( hm->overflow, 4 + hm->unitSize, x); - fn(userData, data + 4); + if(hm->unitSize > 0) { fn(userData, data + 4); } + else { fn(userData, data); } } } diff --git a/src/test/UDPC_UnitTest.c b/src/test/UDPC_UnitTest.c index 9da1f86..e4835eb 100644 --- a/src/test/UDPC_UnitTest.c +++ b/src/test/UDPC_UnitTest.c @@ -232,6 +232,12 @@ void TEST_ATOSTR() UNITTEST_REPORT(ATOSTR); } +void TEST_HASHMAP_itercall_comp(void *unused, char *data) +{ + int temp = *((int*)(data)) / 100; + ASSERT_EQ_MEM(&temp, data - 4, 4); +} + void TEST_HASHMAP() { UDPC_HashMap *hm = UDPC_HashMap_init(0, sizeof(int)); @@ -312,6 +318,8 @@ void TEST_HASHMAP() ASSERT_EQ_MEM(UDPC_HashMap_get(hm, x), &temp, sizeof(int)); } + UDPC_HashMap_itercall(hm, TEST_HASHMAP_itercall_comp, NULL); + // TODO DEBUG /* printf("Size = %d\n", hm->size);