[Mesa-dev] [PATCH 3/3] util/hash_table: Try to hit a double-insertion bug in the collision test
Jason Ekstrand
jason at jlekstrand.net
Wed Feb 4 18:54:54 PST 2015
---
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.
*/
--
2.2.2
More information about the mesa-dev
mailing list