From 2e839aaaed4326ba34dc1f6a055b30fd025a8d3b Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 31 Oct 2011 17:53:12 +0100 Subject: [PATCH] isl_id_alloc: allow isl_ids with the same name but different user value Although isl_ids were documented as being identified by the pair of name and pointer value, this was not implemented as such. Instead, only the name was taken into account. This commit fixes isl_id_alloc to also take into account the user value. We also avoid dereferencing possible NULL names. Signed-off-by: Sven Verdoolaege --- isl_id.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/isl_id.c b/isl_id.c index ef03330e..a3a2ea9d 100644 --- a/isl_id.c +++ b/isl_id.c @@ -66,18 +66,29 @@ error: return NULL; } -static int isl_id_has_name(const void *entry, const void *val) +struct isl_name_and_user { + const char *name; + void *user; +}; + +static int isl_id_has_name_and_user(const void *entry, const void *val) { isl_id *id = (isl_id *)entry; - const char *s = (const char *)val; + struct isl_name_and_user *nu = (struct isl_name_and_user *) val; + + if (id->user != nu->user) + return 0; + if (!id->name && !nu->name) + return 1; - return !strcmp(id->name, s); + return !strcmp(id->name, nu->name); } __isl_give isl_id *isl_id_alloc(isl_ctx *ctx, const char *name, void *user) { struct isl_hash_table_entry *entry; uint32_t id_hash; + struct isl_name_and_user nu = { name, user }; id_hash = isl_hash_init(); if (name) @@ -85,7 +96,7 @@ __isl_give isl_id *isl_id_alloc(isl_ctx *ctx, const char *name, void *user) else id_hash = isl_hash_builtin(id_hash, user); entry = isl_hash_table_find(ctx, &ctx->id_table, id_hash, - isl_id_has_name, name, 1); + isl_id_has_name_and_user, &nu, 1); if (!entry) return NULL; if (entry->data) -- 2.11.4.GIT