Mesa (master): util/hash_table: Try to hit a double-insertion bug in the collision test

Jason Ekstrand jekstrand at kemper.freedesktop.org
Sun Feb 8 01:01:12 UTC 2015


Module: Mesa
Branch: master
Commit: 345e8cc8496b4e6c56105c7396e80d85a37e122c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=345e8cc8496b4e6c56105c7396e80d85a37e122c

Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date:   Wed Feb  4 18:49:11 2015 -0800

util/hash_table: Try to hit a double-insertion bug in the collision test

Reviewed-by: Eric Anholt <eric at anholt.net>

---

 src/util/tests/hash_table/collision.c |   14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/util/tests/hash_table/collision.c b/src/util/tests/hash_table/collision.c
index b76782b..a2210c3 100644
--- a/src/util/tests/hash_table/collision.c
+++ b/src/util/tests/hash_table/collision.c
@@ -36,14 +36,19 @@ main(int argc, char **argv)
    struct hash_table *ht;
    const char *str1 = "test1";
    const char *str2 = "test2";
-   struct hash_entry *entry1, *entry2;
+   const char *str3 = "test3";
+   struct hash_entry *entry1, *entry2, *search_entry;
    uint32_t bad_hash = 5;
    int i;
 
    ht = _mesa_hash_table_create(NULL, NULL, _mesa_key_string_equal);
 
+   /* Insert some items.  Inserting 3 items forces a rehash and the new
+    * table size is big enough that we don't get rehashes later.
+    */
    _mesa_hash_table_insert_pre_hashed(ht, bad_hash, str1, NULL);
    _mesa_hash_table_insert_pre_hashed(ht, bad_hash, str2, NULL);
+   _mesa_hash_table_insert_pre_hashed(ht, bad_hash, str3, NULL);
 
    entry1 = _mesa_hash_table_search_pre_hashed(ht, bad_hash, str1);
    assert(entry1->key == str1);
@@ -60,6 +65,13 @@ main(int argc, char **argv)
    entry2 = _mesa_hash_table_search_pre_hashed(ht, bad_hash, str2);
    assert(entry2->key == str2);
 
+   /* Try inserting #2 again and make sure it gets overwritten */
+   _mesa_hash_table_insert_pre_hashed(ht, bad_hash, str2, NULL);
+   entry2 = _mesa_hash_table_search_pre_hashed(ht, bad_hash, str2);
+   hash_table_foreach(ht, search_entry) {
+      assert(search_entry == entry2 || search_entry->key != str2);
+   }
+
    /* Put str1 back, then spam junk into the table to force a
     * resize and make sure we can still find them both.
     */




More information about the mesa-commit mailing list