2009-09-01 Rodrigo Kumpera <rkumpera@novell.com>
authorRodrigo Kumpera <kumpera@gmail.com>
Tue, 1 Sep 2009 21:03:15 +0000 (21:03 -0000)
committerRodrigo Kumpera <kumpera@gmail.com>
Tue, 1 Sep 2009 21:03:15 +0000 (21:03 -0000)
* metadata-verify.c: Verify the typeref table for duplicates.

svn path=/trunk/mono/; revision=141074

mono/metadata/ChangeLog
mono/metadata/metadata-verify.c

index 806c70799d3532abc5c89a627b39f3b0f183b306..05c7daf76e8cc4b171363ccd9b471d09db7ca952 100644 (file)
@@ -1,3 +1,7 @@
+2009-09-01  Rodrigo Kumpera  <rkumpera@novell.com>
+
+       * metadata-verify.c: Verify the typeref table for duplicates.
+
 2009-09-01  Rodrigo Kumpera  <rkumpera@novell.com>
 
        This reverts r140936 and properly handles interfaces with static methods. The
index 23263c1079fa6a7984204f672db8a7dc1ae80d5f..ba7c199e8b622695f7d0a4dff4908eaf7041ef42 100644 (file)
@@ -3280,7 +3280,35 @@ verify_typedef_table_global_constraints (VerifyContext *ctx)
                }
 
                if (g_hash_table_lookup (unique_types, type)) {
-                       ADD_ERROR_NO_RETURN (ctx, g_strdup_printf ("TypeDef table row %d has duplicate for tupe (%s,%s,%x)", i, type->name, type->name_space, type->resolution_scope));
+                       ADD_ERROR_NO_RETURN (ctx, g_strdup_printf ("TypeDef table row %d has duplicate for tuple (%s,%s,%x)", i, type->name, type->name_space, type->resolution_scope));
+                       g_hash_table_destroy (unique_types);
+                       g_free (type);
+                       return;
+               }
+               g_hash_table_insert (unique_types, type, GUINT_TO_POINTER (1));
+       }
+
+       g_hash_table_destroy (unique_types);
+}
+
+static void
+verify_typeref_table_global_constraints (VerifyContext *ctx)
+{
+       int i;
+       guint32 data [MONO_TYPEREF_SIZE];
+       MonoTableInfo *table = &ctx->image->tables [MONO_TABLE_TYPEREF];
+       GHashTable *unique_types = g_hash_table_new_full (&typedef_hash, &typedef_equals, g_free, NULL);
+
+       for (i = 0; i < table->rows; ++i) {
+               TypeDefUniqueId *type = g_new (TypeDefUniqueId, 1);
+               mono_metadata_decode_row (table, i, data, MONO_TYPEREF_SIZE);
+
+               type->resolution_scope = data [MONO_TYPEREF_SCOPE];
+               type->name = mono_metadata_string_heap (ctx->image, data [MONO_TYPEREF_NAME]);
+               type->name_space = mono_metadata_string_heap (ctx->image, data [MONO_TYPEREF_NAMESPACE]);
+
+               if (g_hash_table_lookup (unique_types, type)) {
+                       ADD_ERROR_NO_RETURN (ctx, g_strdup_printf ("TypeRef table row %d has duplicate for tuple (%s,%s,%x)", i, type->name, type->name_space, type->resolution_scope));
                        g_hash_table_destroy (unique_types);
                        g_free (type);
                        return;
@@ -3294,6 +3322,8 @@ verify_typedef_table_global_constraints (VerifyContext *ctx)
 static void
 verify_tables_data_global_constraints (VerifyContext *ctx)
 {
+       verify_typeref_table_global_constraints (ctx);
+       CHECK_ERROR ();
        verify_typedef_table_global_constraints (ctx);
 }