Mercurial > hg > octave-lyh > gnulib-hg
changeset 13448:6b0f8c52218d
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".
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Sun, 04 Jul 2010 10:54:38 +0200 |
parents | 6d9c300c28a5 |
children | 5b079003ae5a |
files | ChangeLog lib/hash.c |
diffstat | 2 files changed, 17 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-07-04 Jim Meyering <meyering@redhat.com> + + 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". + 2010-07-01 Bruno Haible <bruno@clisp.org> stdbool: Update doc.
--- a/lib/hash.c +++ b/lib/hash.c @@ -1032,13 +1032,20 @@ 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) {