]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Assert that hash table is not being modified during HASH_WALK ip-assert-hash-walk 43/head
authorIgor Putovny <igor.putovny@nic.cz>
Wed, 11 Jun 2025 15:44:38 +0000 (17:44 +0200)
committerIgor Putovny <igor.putovny@nic.cz>
Mon, 16 Jun 2025 11:02:40 +0000 (13:02 +0200)
According to measurements of hash_test, hash table with this assertion added
was not found to be significantly slower than without it on average. Therefore
we conclude that this addition would not hamper the performance of HASH_WALK.

lib/hash.h

index 3c173958ff8146b006c748ddc9715ea4a59d7ea4..4c05c6d7e410001fa38ed462aa72d5ca96767ac4 100644 (file)
 #define HASH_WALK(v,next,n)                                            \
   do {                                                                 \
     HASH_TYPE(v) *n;                                                   \
+    const uint _count = v.count;                                       \
     uint _i;                                                           \
     uint _s = HASH_SIZE(v);                                            \
     for (_i = 0; _i < _s; _i++)                                                \
-      for (n = (v).data[_i]; n; n = n->next)
+      for (n = (v).data[_i]; ({ ASSERT_DIE(v.count == _count); }), n; n = n->next)
 
 #define HASH_WALK_END } while (0)