From fe7c270bddd681e3e56dc28beacf5be425c5e53e Mon Sep 17 00:00:00 2001
From: Přemysl Janouch <p.janouch@gmail.com>
Date: Sat, 11 Dec 2010 03:41:45 +0100
Subject: Check for name collisions in symbol categories.

---
 src/ld-library.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/src/ld-library.c b/src/ld-library.c
index 6348bc6..09f68b5 100644
--- a/src/ld-library.c
+++ b/src/ld-library.c
@@ -249,9 +249,30 @@ load_category_cb (const gchar *base, const gchar *filename, gpointer userdata)
 static void
 load_category_symbol_cb (LdSymbol *symbol, gpointer user_data)
 {
-	/* TODO: Don't just add blindly, also check for name collisions. */
-	ld_symbol_category_insert_child
-		(LD_SYMBOL_CATEGORY (user_data), G_OBJECT (symbol), -1);
+	const gchar *name;
+	LdSymbolCategory *cat;
+	const GSList *children, *iter;
+
+	g_return_if_fail (LD_IS_SYMBOL (symbol));
+	g_return_if_fail (LD_IS_SYMBOL_CATEGORY (user_data));
+
+	cat = LD_SYMBOL_CATEGORY (user_data);
+	name = ld_symbol_get_name (symbol);
+
+	/* Check for name collisions with other symbols. */
+	children = ld_symbol_category_get_children (cat);
+	for (iter = children; iter; iter = iter->next)
+	{
+		if (!LD_IS_SYMBOL (iter->data))
+			continue;
+		if (!strcmp (name, ld_symbol_get_name (LD_SYMBOL (iter->data))))
+		{
+			g_warning ("Attempted to insert multiple '%s' symbols into"
+				" category '%s'.", name, ld_symbol_category_get_name (cat));
+			return;
+		}
+	}
+	ld_symbol_category_insert_child (cat, G_OBJECT (symbol), -1);
 }
 
 /*
-- 
cgit v1.2.3-70-g09d2