silc_hash_table_find_foreach calls once the callback also if
[silc.git] / lib / silcutil / silchashtable.c
index 84549ad8add4fbe025937988d67e15f6c6780908..eb3b180e1141574cba37878e75f8aef9db7ef8aa 100644 (file)
@@ -215,7 +215,7 @@ silc_hash_table_find_internal_all(SilcHashTable ht, void *key,
                                  void *foreach_user_context)
 {
   SilcHashTableEntry *entry, *tmp;
-  bool auto_rehash;
+  bool auto_rehash, found = FALSE;
   SilcUInt32 i = SILC_HASH_TABLE_HASH(hash, hash_user_context);
 
   SILC_HT_DEBUG(("index %d key %p", i, key));
@@ -231,6 +231,7 @@ silc_hash_table_find_internal_all(SilcHashTable ht, void *key,
       if (compare((*entry)->key, key, compare_user_context)) {
        tmp = &(*entry)->next;
        foreach((*entry)->key, (*entry)->context, foreach_user_context);
+       found = TRUE;
        entry = tmp;
        continue;
       }
@@ -241,6 +242,7 @@ silc_hash_table_find_internal_all(SilcHashTable ht, void *key,
       if ((*entry)->key == key) {
        tmp = &(*entry)->next;
        foreach((*entry)->key, (*entry)->context, foreach_user_context);
+       found = TRUE;
        entry = tmp;
        continue;
       }
@@ -248,6 +250,10 @@ silc_hash_table_find_internal_all(SilcHashTable ht, void *key,
     }
   }
 
+  /* If nothing was found call with NULL context the callback */
+  if (!found)
+    foreach(key, NULL, foreach_user_context);
+
   ht->auto_rehash = auto_rehash;
 }