diff options
author | Jason Ekstrand <[email protected]> | 2015-02-04 18:49:11 -0800 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2015-02-07 17:01:05 -0800 |
commit | 345e8cc8496b4e6c56105c7396e80d85a37e122c (patch) | |
tree | 63a7e6e0093fed2e84079f887fbf76bbdbb8b979 /src | |
parent | 623c3a858d9c18f7d62a82597a488e7b54a4a4f4 (diff) |
util/hash_table: Try to hit a double-insertion bug in the collision test
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/util/tests/hash_table/collision.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/util/tests/hash_table/collision.c b/src/util/tests/hash_table/collision.c index b76782b32f7..a2210c3ee8c 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. */ |