summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Stapp <mjs.ietf@gmail.com>2022-10-07 07:30:46 -0400
committerGitHub <noreply@github.com>2022-10-07 07:30:46 -0400
commit9daf964bc89ebeae2d5ae153a645e95dbd120fe7 (patch)
treef96dde92f02ba5f5cdf51be5195722ac8ebef4fd
parenta00621d8b90cb1ddb91557f778c56b89a0b6e1ac (diff)
parent27a6fc42219874a8530f5dd5d44516743ad27ff0 (diff)
Merge pull request #12062 from fdumontet6WIND/hash_list
lib: hash list add function fix
-rw-r--r--lib/typesafe.h9
-rw-r--r--tests/lib/test_typelist.h2
2 files changed, 7 insertions, 4 deletions
diff --git a/lib/typesafe.h b/lib/typesafe.h
index 50c410ad24..8aeabb34e6 100644
--- a/lib/typesafe.h
+++ b/lib/typesafe.h
@@ -850,9 +850,12 @@ macro_inline type *prefix ## _add(struct prefix##_head *h, type *item) \
struct thash_item **np = &h->hh.entries[hbits]; \
while (*np && (*np)->hashval < hval) \
np = &(*np)->next; \
- if (*np && cmpfn(container_of(*np, type, field.hi), item) == 0) { \
- h->hh.count--; \
- return container_of(*np, type, field.hi); \
+ while (*np && (*np)->hashval == hval) { \
+ if (cmpfn(container_of(*np, type, field.hi), item) == 0) { \
+ h->hh.count--; \
+ return container_of(*np, type, field.hi); \
+ } \
+ np = &(*np)->next; \
} \
item->field.hi.next = *np; \
*np = &item->field.hi; \
diff --git a/tests/lib/test_typelist.h b/tests/lib/test_typelist.h
index e3579c67a2..feb42909a8 100644
--- a/tests/lib/test_typelist.h
+++ b/tests/lib/test_typelist.h
@@ -74,7 +74,7 @@ static uint32_t list_hash(const struct item *a)
{
#ifdef SHITTY_HASH
/* crappy hash to get some hash collisions */
- return a->val ^ (a->val << 29) ^ 0x55AA0000U;
+ return (a->val & 0xFF) ^ (a->val << 29) ^ 0x55AA0000U;
#else
return jhash_1word(a->val, 0xdeadbeef);
#endif