summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2010-07-04 10:54:38 +0200
committerJim Meyering <meyering@redhat.com>2010-07-04 11:00:59 +0200
commitfbc47512f3f8e1533a28b4e3eca67938a2f9ebe7 (patch)
treef14d019b6a53d2413477932cf8e0e60cb2a63c26 /lib
parent7773f84fe1aa3bb17defad704ee87f2615894ae4 (diff)
downloadgnulib-fbc47512f3f8e1533a28b4e3eca67938a2f9ebe7.tar.gz
hash: once again explicitly disallow insertion of NULL
* lib/hash.c (hash_insert0): Reinstate just-removed test: inserting a NULL pointer cannot work with these functions. Add a comment with details. This reverts part of the 2010-07-01 commit, 5bef1a35 "hash: extend module to deal with non-pointer keys".
Diffstat (limited to 'lib')
-rw-r--r--lib/hash.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/hash.c b/lib/hash.c
index 4c359a4721..15630be21e 100644
--- a/lib/hash.c
+++ b/lib/hash.c
@@ -1032,13 +1032,20 @@ hash_rehash (Hash_table *table, size_t candidate)
hash_insert, the only way to distinguish those cases is to compare
the return value and ENTRY. That works only when you can have two
different ENTRY values that point to data that compares "equal". Thus,
- when the ENTRY value is a simple scalar, you must use hash_insert0. */
+ when the ENTRY value is a simple scalar, you must use hash_insert0.
+ ENTRY must not be NULL. */
int
hash_insert0 (Hash_table *table, void const *entry, void const **matched_ent)
{
void *data;
struct hash_entry *bucket;
+ /* The caller cannot insert a NULL entry, since hash_lookup returns NULL
+ to indicate "not found", and hash_find_entry uses "bucket->data == NULL"
+ to indicate an empty bucket. */
+ if (! entry)
+ abort ();
+
/* If there's a matching entry already in the table, return that. */
if ((data = hash_find_entry (table, entry, &bucket, false)) != NULL)
{