From b67ca8536041145da8bbd3138cb7df174bd0e71d Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sun, 22 Apr 2007 18:19:39 +0000 Subject: [PATCH] Allow NULL id for silc_idcache_add. --- lib/silcapputil/silcidcache.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/silcapputil/silcidcache.c b/lib/silcapputil/silcidcache.c index bc18e1ab..7340414a 100644 --- a/lib/silcapputil/silcidcache.c +++ b/lib/silcapputil/silcidcache.c @@ -123,7 +123,9 @@ silc_idcache_add(SilcIDCache cache, char *name, void *id, void *context) { SilcIDCacheEntry c; - if (!cache || !id) + if (!cache) + return NULL; + if (!name && !id && !context) return NULL; /* Allocate new cache entry */ @@ -137,15 +139,20 @@ silc_idcache_add(SilcIDCache cache, char *name, void *id, void *context) SILC_LOG_DEBUG(("Adding cache entry %p", c)); - /* Add the new entry to the hash tables */ - if (silc_idcache_find_by_id_one(cache, id, NULL)) { - SILC_LOG_ERROR(("Attempted to add same ID twice to ID Cache, id %s", - silc_id_render(id, cache->id_type))); - SILC_ASSERT(FALSE); - goto err; + if (id) { + /* See if this entry is added already to cache */ + if (silc_idcache_find_by_id_one(cache, id, NULL)) { + SILC_LOG_ERROR(("Attempted to add same ID twice to ID Cache, id %s", + silc_id_render(id, cache->id_type))); + SILC_ASSERT(FALSE); + goto err; + } } - if (!silc_hash_table_add(cache->id_table, id, c)) - goto err; + + /* Add the new entry to the hash tables */ + if (id) + if (!silc_hash_table_add(cache->id_table, id, c)) + goto err; if (name) if (!silc_hash_table_add(cache->name_table, name, c)) goto err; -- 2.24.0